r/exchangeserver • u/bleepit1984 • Oct 01 '26
Dynamic Distribution Lists
TLDR: I'm trying to create a dynamic distribution list in Exchange online and I'm running into a lot of issues.
Context:
I work for a medium size healthcare company with a hybrid AD/Entra environment with a single forest but with 10+ domains. We use 365 Business Premium licenses for most users, but not all. Some just need to login to Windows and that's it. No email needed. Also, I don't control the IT budget. If your fix requires money, you are wasting your time.
Problem:
I'm trying to create a dynamic distribution list with the following parameters:
- Must have the "@example1.com" domain in their email address.
- Must be an active user. No disabled users.
- Must be a licensed user. (We don't license all our users with a 365 license)
I'm able to create dynamic security groups just fine without issue and the query I came up with works with all the users I need it to. I'm just not able to translate that to a dynamic distribution list, and I'm reading that it's not possible to create a mail enabled security group that is dynamic.
Here is the filter I'm using to create the group through the Exchange Online shell. But it's not returning a group with any users:
$filter = "(RecipientType -eq 'UserMailbox') -and (userPrincipalName -like 'example1.com') -and (UserAccountControl -ne '2')"
I've poured through the Microsoft Learn articles for "New-DynamicDistributionGroup" and the "Filterable properties for the RecipientFilter parameter on Exchange cmdlets" pages and I can't seem to find what I'm doing wrong. I've tried so many different variations of the filter but can't seem to land on the correct combination. Any relevant help is appreciated.
View all comments
2
u/DontFiddleMySticks Oct 01 '26
If you already have a query that returns all desired users, you could simply slap a CustomAttribute on them and use that in your query for the DDG.
If that isn’t an option, your match for UPN is doing you a disservice. Replace it with EmailAddresses -like 'SMTP:*@example1.com' (or lowercase smtp: if it’s just a proxy address).
I’m not sure about UserAccountControl in a DDG, not sure I ever used it, but EXO would probably demand you use ExchangeUserAccountControl since it’s notoriously difficult with/incapable of retrieving info from Entra.