Create Dynamic Distribution Groups in Office 365

Hello

Today we’ll see how to create dynamic distribution groups in Office 365. The easy way is to use the admin web portal and enable  “Command Logging”.

Create Dynamic Distribution Groups - Show Command Logging

Create Dynamic Distribution Groups – Show Command Logging

Create Dynamic Distribution Groups

Here are the lines :

New-DynamicDistributionGroup -Name 'All It For Dummies Mailboxes' -Alias 'everyone' -OrganizationalUnit $null -IncludedRecipients 'MailboxUsers' 
Set-DynamicDistributionGroup -Identity 'All It For Dummies Mailboxes' -Name 'All It For Dummies Mailboxes' -Alias 'everyone' -Notes 'All It For Dummies Mailboxes from Office 365 !' -IncludedRecipients 'MailboxUsers'

This will create a distribution group with all Office 365 mailboxes in it, think of it as a “All Employees” distribution list.

You can enable some recipient filters to create more targeted dynamic distribution groups :

New-DynamicDistributionGroup -Name 'IT Department' -Alias 'IT' -OrganizationalUnit $null -IncludedRecipients 'MailboxUsers' -ConditionalDepartment @('IT') 
Set-DynamicDistributionGroup -Identity 'IT Department' -Name 'IT Department' -Alias 'IT' -Notes 'This is the IT department !' -ConditionalDepartment @('IT') -IncludedRecipients 'MailboxUsers'

This will create a dynamic distribution group for your IT department, base on the “Department” attribute from your Active Directory.

Check the members

Because of the nature of dynamic distribution groups, you can’t see the members like standard distribution groups, you need to use PowerShell and “evaluate” members :

Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup -Identity 'IT Department').RecipientFilter -ResultSize unlimited
Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup -Identity 'All It For Dummies Mailboxes').RecipientFilter -ResultSize unlimited
Create Dynamic Distribution Groups - Get Member

Create Dynamic Distribution Groups – Get Member

The members are completely dynamic and are calculated when the list is used.

You can see all Dynamic Distribution Groups members with this :

Get-DynamicDistributionGroup | % {
    Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup -Identity $_.Identity).RecipientFilter -ResultSize unlimited | Add-Member -NotePropertyMembers @{'DynGroup'=$_} -PassThru | select Name,RecipientType,DynGroup
}

If your Active Directory is well filled, you can use those dynamic groups to create your department lists, your sites lists, and every custom attribute you use.

Of course, those dynamic distribution groups also support moderation, delegation and delivery options like normal distribution groups.Moderation can be a pretty good idea if you create that kind of distribution groups with a lot of members.

Bonus : If you use only PowerShell to create the dynamic distribution groups, you can use the Office attribute :

New-DynamicDistributionGroup -Name 'Office 1 employees' -RecipientFilter { ((RecipientType -eq 'UserMailbox') -and (Office -eq 'Office 1')) }

3 thoughts on “Create Dynamic Distribution Groups in Office 365

  1. I wanted to ask and expand on your Bonus script: Say I wanted to expand on the \’Office 1\’ to include \’Office 2\’ or more, how would I do that, I have tried (Office -eq \’Office 1\’,\’Office 2\’) to no avail. I want to thank you in advance if you have an answer.

    • You can use: New-DynamicDistributionGroup -Name \’Office 1 employees\’ -RecipientFilter { ((RecipientType -eq \’UserMailbox\’) -and ( (Office -eq \’Office 1\’) -or (Office -eq \’Office 2\’) ) ) }

  2. Hi,

    informative blog, thank you.

    I just wondered if you knew of a way to create a DDG that would include a director and recurse through for all their managers, their managers direct reports and so forth?

    We have a very large org and this would be a great facility to have.

Leave a Reply