On-prem Exchange Dynamic List
If you have a medium to large AD environment with on-prem Exchange servers, chances are that you need to mess with dynamic distribution lists. Here I will show you how to make one excluding all disabled users and more.
To Create a Dynamic Distro List:
Example:
New-DynamicDistributionGroup -Name "Washington Management Team" -RecipientFilter "(RecipientTypeDetails -eq 'UserMailbox') -and (Title -like 'Director*' -or Title -like 'Manager*') -and (StateOrProvince -eq 'WA')" -RecipientContainer "North America"
To Update a Dynamic Distro List:
Example:
Set-DynamicDistributionGroup -identity “housewide” -RecipientFilter ""RecipientFilter Examples:
- RecipientType -eq 'UserMailbox'
- MemberOfGroup -eq 'CN=GroupName,OU=OUName,OU=Test,DC=ZengroTrust,DC=com'
- -not(MemberOfGroup -eq 'CN=GroupName,OU=OUName,OU=Test,DC=ZengroTrust,DC=com')
- UserAccountControl -ne 'AccountDisabled, NormalAccount'
To update a list called TestDL to include all user mailboxes that are not in TestGroup and enabled:
Set-DynamicDistributionGroup -identity “TestDL”
-RecipientFilter "((RecipientType -eq 'UserMailbox')
-or (RecipientType -eq 'MailUser'))
-and (-not(MemberOfGroup -eq 'CN=TestGroup,OU=TestOU,DC=ZengroTrust,DC=com'))
-and (UserAccountControl -ne 'AccountDisabled, NormalAccount')"