Dynamic Distribution Lists are an easy way to maintain lists without having to constantly maintain lists.
Basic creation is simple – you can do that right from EAC and select which type of recipients in the organization should be included.
More complex options exist but are accomplished with PowerShell. For instance, you want to create a distribution list that includes all Exchange Mailbox users, but you don’t want to include Shared Mailboxes, Equipment or Resource Mailboxes, or any users with attributes that match.
If you want to use custom attributes where you have AAD Connect there’s a bit more you need to do. I’ve document that here: https://catastrophe.wiredwolf.com/azure-ad-connect-and-custom-attributes/
This is where it gets a bit tricky. You can’t mix operators and stay sane, so it’s important to know how to format the command with not double not nor negatives (joke).
Creating a List:
New-dynamicdistributiongroup -name “DGNAME” `
-recipientfilter {((RecipientType -eq ‘UserMailbox’) `
-and (CustomAttribute1 -ne ‘NoMember‘) `
-and (-not(RecipientTypeDetailsValue -eq ‘SharedMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘GuestMailUser’)) `
-and (-not(Name -like ‘SystemMailbox{*’)) `
-and (-not(Name -like ‘CAS_{*’)) `
-and (-not(Company -eq ‘Acme‘)) `
-and (-not(RecipientTypeDetailsValue -eq ‘MailboxPlan’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘DiscoveryMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘PublicFolderMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘ArbitrationMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘AuditLogMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘AuxAuditLogMailbox’)) `
-and (-not(RecipientTypeDetailsValue -eq ‘SupervisoryReviewPolicyMailbox’)))} `
-managedby “admin@yourdomain.com” `
-DisplayName “Dynamic Distribution Group Name” `
-RequireSenderAuthenticationEnabled $false `
-MemberDepartRestriction closed `
-MemberJoinRestriction closed
I’ve added a couple of options as an example of how far you can go with RecipientType and RecipientTypeDetails. If synchronized with an on-premises AD you can easily add attributes to the account, such as Company, or CustomAttribute1, at which point you can use these attributes to further hone the scope of your Dynamic Distribution List.
If you’ve created the dynamic distribution list already you can always edit it:
replace new-dynamicdistributiongroup -Name “DGNAME” with set-dynamicdistributiongroup -identity “DGNAME”
Getting details from a single list – export to CSV
Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup DGNAME).RecipientFilter -OrganizationalUnit $group.RecipientContainer | select Name, DisplayName, PrimarySMTPAddress, RecipientType*, WindowsLiveID | export-csv “C:\CSV-PATH\DynDG-DGNAME.CSV” -NoTypeInformation