Create Dynamic Distribution List based on email domain
I spent a while looking around for a solution for this issue – at first, I wasn’t able to create a recipient filter that worked on a user’s domain.
I eventually found a solution that worked by filtering on the WindowsLiveID property, which is pretty much always the same as the primary smtp address and user principal name.
You’ll first need to connect to Exchange Online via Powershell.
The following line will create a dynamic distribution group filtered by the users’ domain:
New-DynamicDistributionGroup -name "All Users - Domain Name" -RecipientFilter "(RecipientTypeDetails -eq 'UserMailbox') -and (WindowsLiveID -eq '*@domain.com')
These lines will confirm that the correct users were added to the new dynamic distribution group:
$group = Get-DynamicDistributionGroup "All Users - Domain Name" Get-Recipient -RecipientPreviewFilter $group.RecipientFilter
When running this, be sure to update the @domain.com and All Users – Domain Name values to your appropriate values.