Display members of dynamic distribution groups using PowerShell

Display members of dynamic distribution groups using PowerShell

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

How to list members of a single dynamic distribution group

Viewing current dynamic distribution group (or dynamic distribution list a.k.a. DDL) membership in Exchange is very easy thanks to the Get-Recipient PowerShell cmdlet and its –RecipientPreviewFilter parameter. This applies to Exchange 2019, 2016, 2013, 2010 and 2007, as well as Exchange Online.

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

Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup <name of group>).RecipientFilter -OrganizationalUnit $_.RecipientContainer

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 -OrganizationalUnit $_.RecipientContainer | Select Displayname | Export-Csv "<path of target CSV file>"

How to get members of multiple dynamic distribution groups

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 formatted 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 -OrganizationalUnit $group.RecipientContainer | 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

Tools for Exchange Server

Recommended articles

How to migrate from Exchange Server 2016/2019 to Microsoft 365

How to migrate from Exchange Server 2016/2019 to Microsoft 365

Migrating Exchange data to the cloud is not rocket science – explore your options and launch the migration stress-free. As you may already know, Exchange Server 2016 and 2019 have reached end of life and are no longer officially supported by Microsoft. If your organization still uses either of these platforms to manage email, contacts, calendars, and tasks, keep in mind that: Your environment may become vulnerable to newly discovered security threats – Microsoft will no longer provide security updates for Exchange 2016 and 2019 (unless you’ve enrolled in the Extended Security Update program, which ends in October 2026). Your emails may get blocked – Microsoft has started to throttle and block emails sent from unsupported Exchange Server versions to Exchange Online (as I covered in this article). That said, migrating to a supported platform is now the only viable long-term option for keeping your organization’s email environment secure, supported, and fully operational. If your organization wants or needs to keep things on‑premises (and continue using Microsoft’s solutions for that), upgrading to Exchange Server Subscription Edition (SE) is the only path forward. But given Microsoft’s clear preference for its cloud services – evident in the faster rollout of new features and the many security capabilities available exclusively in Microsoft 365 (Office 365) – now is a great time to leave your on‑prem environment behind and migrate to Exchange Online as part of Microsoft 365. While switching over to a new platform might seem like a rough ride, I’ll show you some easy ways to follow when migrating mailboxes from Exchange Server 2016/2019 to Microsoft 365. How to prepare for email migration to Microsoft 365 Before you start the migration process, you need to make sure your environment is ready for the move. For this purpose, you can use this guide in the Microsoft 365 admin center – it will help you connect your organization to Microsoft 365 and integrate your existing user accounts with Microsoft Entra ID. Microsoft also recommends completing the steps below: Set up an SPF record to determine valid email sources for your organization’s Microsoft 365 domain. Set up the Exchange Online Protection service as a means of protection against spam and malware. If you’re behind on updates, make sure to install the latest Cumulative Update (CU). And here is my quick, less obvious Microsoft 365 migration checklist: Verify if your software will work in Microsoft 365 (especially when it comes to server software). Microsoft 365 migration might be the time you learn that there is crucial legacy software that half the company uses and which is hard to replace. Encourage the whole company to clean up projects. It’s much easier to do this before the migration and start fresh. Gather as much information about your on‑premises environment as possible. For example, you might need to recreate access roles and permissions from scratch in the cloud or set up mail flow rules. Without prior research, it will be much more difficult. Verify if you need to migrate service accounts. There can be a lot of them on‑premises and in most cases, you won’t need them after the move. Review mailbox size limits in Exchange Online before migration to see which licenses you’ll need and whic
How to connect and remotely manage Microsoft 365 with PowerShell

How to connect and remotely manage Microsoft 365 with PowerShell

Microsoft 365 web interface was designed to make it easier to manage your tenant right down to its administrative bowels. On the one hand it really is quick and simple to navigate, on the other it definitely lacks some advanced configuration options so loved by sysadmins. Luckily there is the mighty PowerShell coming to the rescue! You should already know its potential, which can also be utilized in Microsoft 365. Find out how.
New-ComplianceSearch: how to use the newer version of Search-Mailbox

New-ComplianceSearch: how to use the newer version of Search-Mailbox

Microsoft retired the Search-Mailbox cmdlet – now what? Discover how to use New-ComplianceSearch, its key advantages and how to make the switch seamlessly.

Comments

  1. Hello unfortunally this commands do not work for me. I just get a list of all users our domain.
    Our AD is like: Domain -> Frontend -> Users -> Location1, Location2 … We have one DDG for each Location.
    Now i want to get all members of ddg.location1 so i tried this:

    Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup “DDGLocation1”).RecipientFilter -OrganizationalUnit $location1.RecipientContainer

    Like i already said i just get a list of all users. Is there a way to specify just the location1 OU?

    • avatar
      Adam the 32-bit Aardvark says:

      You might need to specify the location manually. You don’t specify the variable $location1 anywhere, so it won’t work this way. Try running the cmdlet below to see each DDG location:
      Get-DynamicDistributionGroup | FT name,RecipientContainer

  2. avatar
    Steven Foster says:

    Antonio Segovia – thank you so much for your post with the correction on needing the -OrganizationalUnit. I was trying to get the result of a DDL and it was coming out totaly wrong and thought my filter was jacked. Nope just needed that additional switch and got exactly what ! should have.

  3. $FTE = Get-DynamicDistributionGroup “hq”

    Get-Recipient -ResultSize Unlimited -RecipientPreviewFilter $FTE.RecipientFilter -OrganizationalUnit $FTE.RecipientContainer | Format-Table Name,Primary*

  4. avatar
    Antonio Segovia says:

    For those who arrive to this page trying to obtain the membership of a Dynamic DG. Please note that you MUST specify the -OrganizationalUnit with the RecipientContainer.

    So instead of:
    Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup ).RecipientFilter

    Use this:
    Get-Recipient -RecipientPreviewFilter (get-dynamicdistributiongroup ).RecipientFilter -OrganizationalUnit (get-dynamicdistributiongroup ).RecipientContainer

    Failing to do this will result on getting the wrong membership.

    • avatar
      Adam the 32-bit Aardvark says:

      Thanks for the comment, you’re right!
      I don’t know how I missed this part from the first examples, it’s updated now.

    • avatar
      Adam the 32-bit Aardvark says:

      Thanks for the comment, I’m glad you found the article useful.
      To get the list from a CSV file, use the following cmdlet:
      $DDL = import-csv "<target CSV file path>" ; $DDL

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>

*

CodeTwo sp. z o.o. sp. k. is a controller of your personal data.
See our Privacy Policy to learn more.