Display members of dynamic distribution groups using PowerShell

Applies to Exchange 2016, Online, 2013, 2010 and 2007.

Viewing current dynamic distribution group membership on Exchange Server is very easy thanks to the Get-Recipient PowerShell cmdlet and its -RecipientPreviewFilter parameter.

Display members of dynamic distribution groups using PowerShell

To display members of a single dynamic distribution group simply run:

Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup <name of group>).RecipientFilter

You can also easily export members of any distribution group to a CSV file by running:

Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup <name of group>).RecipientFilter | Select Displayname | Export-Csv "<path of target CSV file>"

Displaying members of all dynamic distribution groups is not much harder. The trick is to display them in an orderly way instead of lumping them all together. A good way of achieving this is by using a formated table for each group with the group’s name as the header. Here is how to do this:

foreach ($group in (Get-DynamicDistributionGroup)) {Get-Recipient -RecipientPreviewFilter $group.RecipientFilter | ft @{Expression={$_.displayname};Label=($group).name}}

The results of the command above can be exported to a file, but since they are already formated, it cannot be a CSV file.

foreach ($group in (Get-DynamicDistributionGroup)) {Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer | ft @{Expression={$_.displayname};Label=($group).name} | Out-File "c:\<path>.txt" -Append}

Another option is to generate a list of dynamic group memebers with their group membership provided in a separate column:

foreach ($group in (Get-DynamicDistributionGroup)) {Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer | Select DisplayName,@{n="Group";e={$group.name}}}

This time we can export the result of the script to a comma separated file:

foreach ($group in (Get-DynamicDistributionGroup)) {Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer | Select DisplayName,@{n="Group";e={$group.name}} | Export-Csv "<target CSV filepath>" -Append}

To export members of separate dynamic distribution groups to separate CSV files use a variation of the below script:

foreach ($group in (Get-DynamicDistributionGroup)) {Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer | Select DisplayName | Export-Csv "c:\$group.members.csv"}

Further reading

How to split CSV file into multiple files using PowerShell

Central management of email signatures on Exchange and Office 365

Display members of dynamic distribution groups using PowerShell by

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>