Export all distribution Group and all members in Exchange and Office 365

In some situations, we have to Export all the Distribution group/Unified Groups and all the members of it to a CSV file. There is no command let available to retrieve the distribution group and distribution group members in bulk. The pipeline won’t work in this case.


****2021 Export all Unified Groups as well***

**** Export all the Distribution group and Distribution Group managers as well***

***Export all the Dynamic Distribution group and Dynamic Distribution Group managers as well***

Recipient OU
Primary SMTP address
Distribution Group
Distribution Group Primary SMTP address
Distribution Group Managers
Distribution Group OU
Distribution Group Type
Distribution Group Recipient Type
Not Allowed from the Internet

I have written a script that will make Exchange Administrators’ life Easy to export distribution group and its members.

Requires Exchange Management Shell – For Option 9 and 10 you will need Exchange Online Shell

.\DistributionGroupMemberReport.ps1 – It Can Display all the Distribution Group and its members on a List

Or It can Export to a CSV file

Download the Script

Browse the Shell to the Appropriate Location

Run it as above

The output of the CSV file looks like Below

You can add some more entries if required


Download the Script

How to use this Script for Office 365 – 

Local desktop. PowerShell – Run as Administrator


Make Sure your Execution Policy is set to RemoteSigned or Unrestricted

Set-ExecutionPolicy RemoteSigned

my Case is unrestricted.

To Get Execution Policy Status




Now Run the Script – It should work.

Git Public Repository Link –

azure365pro/DistributionGroupMemberReport (github.com)


About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Office Server and Services MVP , Publisher of Azure365pro.com. Specialized in Office365 / Microsoft Exchange / Virtualization , Sathesh is an Messaging Expert supporting/Designing/Deploying many medium size businesses to large enterprises when it comes to Corporate messaging and Virtualization Infrastructure

Check Also

Azure B2C White label URLs with Azure Front Door

Azure B2C is allowing white label URLs through Azure Front Door now. it was a …


  1. Anatol Maitchovcow

    Sorry I Execute you script and result on error, and segun QZ Is force the script Unlimited result who modificate.

    Method invocation failed because [System.Management.Automation.PSObject] doesn’t contain a method named ‘op_Addition’.
    At C:\TEMP\dist.ps1:5 char:10
    + $Report+= <<<< Get-distributionGroupMember -identity $_.identity | select @{Name='Distribution Group'; Expression={[S
    tring]::join(";", $GroupName)}}, Name, PrimarySmtpAddress}
    + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

  2. Satheshwaran Manoharan

    I have sent the script in a text file to your email , Rename to PS1 and run it .

    it should work.

    Some spaces in the script might give out issues like this

    • Hi!

      I executed this but it can’t display that groups where is only one member in.
      Many DG’s are missing now from the report.

      • Satheshwaran Manoharan

        Do you have Child domains in your environment ?
        Can you run Get-DistributionGroup “missing DG name”
        And Check what happens ?

    • hello satheshwaran,

      i am also getting below error while rnning this script ,please send me text file which i can convert into PS1 at my end ..

      Method invocation failed because [System.Management.Automation.PSObject] doesn’t contain a method named ‘op_Addition’.
      At D:\temp\DistributionGroupMemberReport.ps1:14 char:11
      + $output += <<<< $UserObj
      + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
      + FullyQualifiedErrorId : MethodNotFound

    • Dear Satheshwaran Manoharan,

      As i have checked your script its working but given result is not correct because given members list not member of particular Dynamic distribution group. So please help.

  3. Excellent , Thank you

  4. Hi,
    Great script. Thanks. However, I have not been succesful in importing a csv-file. Could you please elaborate on how to import the contents of the file.

    • Satheshwaran Manoharan

      Hi Ben,
      I don’t have the script ready,

      But this is what the syntax would be.

      Get-Distributiongroup | select-object Name,Email* so n so . Export to CSV

      Import-CSV C:Filename.csv | Foreach{new-DistributionGroupmember $_.DGNAME } add if any more parameters needed

      Now create those distribution groups in the other end.

      Then use the exported file and you can import it back
      Import-CSV C:Filename.csv | Foreach{Add-DistributionGroupmember DGNAME -Member $_.Members}

  5. Thanks for the script! It works as described. CSV function is also working as well. It made life easier exporting out all the DLs.

    • Satheshwaran Manoharan

      Thank you for your Comments Homer

      • Total DLS 16162 (approx. users 140,000)

        Types of DLS = (Mail Universal Security Group
        Mail Universal Distribution Group
        Dynamic Distribution Group
        Mail Non-Universal Group)

        Need to export below data in column wise

        DL Display name
        DL Primary SMTpAddress
        members count
        AcceptMessagesOnlyFromSendersOrMembers (AcceptMessagesOnlyFrom ; AcceptMessagesOnlyFromDLMembers)
        Last Modified Time

  6. Hi Satheshwaran:

    I am able to run this script. I don’t have any errors in executing the script, however to my surprise:
    Option 1: Display in Exchange Management Shell
    works pretty much good and displays all the results for me in my environment.

    Option 2: Export to CSV File
    Script is not executing or i can say it is not completing and throwing below kind of errors.

    WARNING: The object app********.com/**/******/HQLO-CS National Accounts (350) has been corrupted, and it’s in an
    inconsistent state. The following validation errors happened:
    WARNING: Property expression “HQLO-CSNationalAccounts(350)” isn’t valid. Valid values are: Strings formed with
    characters from A to Z (uppercase or lowercase), digits from 0 to 9, !, #, $, %, &, ‘, *, +, -, /, =, ?, ^, _, `, {, |,
    } or ~. One or more periods may be embedded in an alias, but each period should be preceded and followed by at least
    one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be
    mapped to a best-fit US-ASCII string in the e-mail address, which is generated from such an alias.

    It seems, some objects were corrupted in AD and i suspect they are not letting the results to be written in CSV file. How can i avoid this situation and get the results written in CSV file?

    • Satheshwaran Manoharan

      You should run , Get-DistributionGroup “ProblemGroup”

      Check is there any empty spaces in the end . or you can try removing special character.

      This problem happens. if they are very old distribution groups . migrated from exchange 2000

      • Hi Satheshwaran:

        Thanks for the information. Is there any way, i can ignore these kind of corrupted groups and export remaining good groups to CSV. I need this information for one my customer and not able to export it by any other ways.

        This script meets my requirement, however got stuck here 🙁

        Thanks, Sambasiva

  7. Hi Satheshwaran?
    why when i run this script?the “distribution group” display like this “?-??”
    My Server is CHN

    • Satheshwaran Manoharan

      Hey Micogo,

      Can you run Get-DistributionGroup and Get-distributiongroupmember

      make sure those cmdlets work fine. ?

  8. Awesome script. Thank you!

  9. Could you please explain me how I can filter/execute your script on specifiek OU
    (I don’t want to know all the distribution groups in AD, only in a specific OU)

  10. I am getting attached error while running given script…”Unexpected token ‘C:DG>.DistributionGroupMemberReport.ps1’ in expression or s
    At C:DGDistributionGroupMemberReport.ps1:13 char:47
    + [PS] C:DG>.DistributionGroupMemberReport.ps1 <<<<"

    • Satheshwaran Manoharan

      Right Click , Run as administrator , and give a try.

      • I’ve been having the same problem:

        ‘C:\DG>.\DistributionGroupMemberReport.ps1? in expression or s
        At C:\DG\DistributionGroupMemberReport.ps1:13 char:47
        + [PS] C:\DG>.\DistributionGroupMemberReport.ps1 <<<<"

        I tried right running power shell as administrator and still get the same symptom.

        • Satheshwaran Manoharan

          Can you run – Get-distributiongroup


          and make sure . you have permission to run these commands in exchange management shell

  11. Is there a possibility to (only) read out the hidden D-groups?
    Thanks a lot!

    • Satheshwaran Manoharan

      Replace Get-Distribution Group with Get-DistributionGroup | Where-Object{$_.HiddenFromAddresslistsEnabled -eq “True”}

      It should export hidden ones


  12. Great script, sure saved me a lot of time. Thank you!

  13. thank you very much
    I can run it without problem.
    but it does not show empty DL or DL contain only other DL.
    I tried to modify the script PS but it doesn’t work.

    Have you an idea ?

  14. Hi, thanks for the great script! Unfortunately, I receive “?” marks in names due to a different language. Is there any way how to fix a wrong coding?

  15. I’d like to run this script as a scheduled job, how can I make it default to option two csv, so it runs from the scheduled job?

    • Satheshwaran Manoharan

      Just open the scrip . Take of the Switch functions . Take only the option content you want . paste it to a new file.
      That should help you

  16. Awesome script, makes keeping lists in check alot easier – thanks

    would it possible to output the distribution lists email address as well?


  17. Really good Script.

    what can i do so the script also exports the OU name as well.

  18. Very good script! Did exactly what I needed. Thank you!!!!!!!

  19. Hello Team ,

    How to find out Dl member count. ( not list i want only member count )

    Is there any way ?

  20. We are going to Remove Inactive Distribution Groups & Members of that Groups of exchange 2007 Distribution Group.

    Kindly Help me on below:

    how do I identify or export Inactive Distribution Groups, Last email send to that Distribution Group,Inactive Users in DG.?

  21. Hi!

    Is there any command to export the distribution groups in exchange 2003?

    Arun Prasath M

  22. Hi Satheshwaran,

    is there a script to import bulk security groups in AD 2008 using CSV file. can you please send some samples.


  23. Hi Satheesh, Really nice article and read multiple article from you which is very helpful my day to activity as well critical time. I have a 600 DL’s in forest A exchange server. I want to export all DL’s along with members and owners to forest B exchange server. Is there any script to perform the specified task. I am aware to migrate groups via ADMT 3.2, but exchange attribute no option via ADMT and I can export via ldifde for group information, but i want to perform as a bulk migration. Could you share any step by step approach in order to finish the task ASAP instead of going 3rd party tool.


  24. Your is awesome but I want to get the complete list of member of each DL including member of nested DL’s members. So that i can get complete list of all DL members. looks like this is not possible in current PS script. Any suggestion?

  25. Hi Satesh,
    Waiting for modification where we can see nested DLs as well.

  26. Hi Satesh,
    Great Script it is very helpful. How do I modify or what command could I use to only get a list of mail contacts that do not belong to any groups.
    Thanks again for all your help.

  27. Hi Satheshwaran,

    Is it possible that we can allow or assign rights only to 2-3 mailbox users who can view the members of DL group and rest restricted ?

    I found https://alashcroft.wordpress.com/2012/04/03/hiding-distribution-group-membership-exchange-2010/ but this will only restrict all users and none of users then can expand DL group.

    Harmeet Chauhan

  28. Just use this, easier way


  29. Where does it show the member of the DL?

    Thank you,

    • Satheshwaran Manoharan

      Put it in Excel – Filter the Distribution Group Column. you can see the members.

      • Hi Satheshwaran.

        Awesome script but I am having some issues.
        1. the moment I chose option 2; it constantly prompts the open with windows which in turn open more than 1000 Rundll and impacted the server.

        2. It does not display the group members. I have tried using the excel filter but still nothing. Also I don’t see a field for Members.


  30. what is cloud server hosting

    Certainly, being able to find cheap web space will give you numerous benefits.
    Migrating the results from the old web hosting profile on the managed vps is a critical process.
    If you use Windows proprietary applications, then concentrating
    efforts oon Windws web hosting can bbe a great decision.

  31. Saved me many hours of doing it manually. Your script also helps to find duplicate errors. Great job.

  32. There is certainly a lot to find out about this
    subject. I love all the points you made.

  33. Hello Satheshwaran Manoharan,

    ist it possible to rewrite some lines in this script to get the same resulst just fpr securitygroups?


  34. Hi Satheshwaran,

    I tried to run your awesome script against Exchange online by adding
    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
    Import-PSSession $Session

    to the beginning of the script.
    That worked well, but then I log in as admin for my customer and the script returns an access denied error. I even tried to point the script to an empty Fat32 USB drive with no security.

    Have you succeeded to run the script against Exchange Online and creating csv files from it?

    So far i ended up copying the screendump, but the email adresses get abreviated. So that doesn’t work either.

    Thanks for all the help


  35. Hi .. I have around 300+ distribution groups in Exchange 2010 with count less different patterns of members. I am upgrading to exchange 2016. If I export all the distribution groups to a csv file, how can I import all in exchange with same members in those groups.

  36. Did you ever implement expansion of nested groups?


  37. Did you ever implement expansion of nested groups?


    • Satheshwaran Manoharan

      Yes, It will show Group 1 has members NestedGroup1.
      and nested group1 members in the same list below separately.

  38. Hi Manoharan.

    I need your help,

    I have to check how many DL have more then 1000 members.

    could you please write the script for the same, i am just new to power shell and don’t know how to write script.

    Amreesh Kumar

  39. Hi Manoharan,

    Thanks for this script. I would like to filter only recipient type as ” Mail contact ” and get the details. Can you help me where do i put the filter in this script. my intention is to export the external email address from all the DL.

  40. Well I really enjoyed studying it. This subject provided
    by you is very constructive for good planning.

  41. Hi Sathesh, can it also list the access rights each of the member hold on the respective distribution group?

  42. Hi,

    I have set of users and planned to migrate into O365, need get users who are all has the permission to send email DL and dynamic DL like(below command). how to get that?

    Get-DistributionGroup | where {$_.AcceptMessagesOnlyFromSendersOrMembers -eq “user name”} | fl name, acceptmessagesonlyfromsendersormembers | format-list

  43. Hello
    could send me the scripts that works in exchange 2016, i am getting lots errors when i try to run the current one.

    thank you

  44. How do I limit the script to an organizational unit?

    I don’t need all Active Directory lists.

    • You have to find below line – as per your option you using in the script and modify below like
      Old Line –
      $AllDG = Get-DistributionGroup $Dgname -resultsize unlimited
      Replace with – Specified OU. Change the OU name as your Active Directory name
      $AllDG = Get-DistributionGroup $Dgname -organizationalunit "domain/ou" -ResultSize Unlimited

  45. Hi,

    I want to export the list of users who can send emails to a DL. The exported list should contain the email address of the members who are authorized to send emails to the DL. Can you please help.

  46. This is great for exporting all of the necessary information from one tenant. Thank you for posting it. Any idea how to take this list and import it into another tenant?

  47. Hi Satheshwaran, thanks you for this excellent script. I am not sure is this is still running but here is my situation:

    I have 1800 distribution groups in Exchange 2016. These are all synchronized in O365 as distribution lists but are mastered on premises. I need to have these mastered in O365 and keep the same DL name and members so that I can close the exchange 2016 environment

    I am experimenting with 6 distribution groups in my test environment which is set up the same, and have run the script and have a csv file with with the distribution groups and members.

    I want to move around 50 to 100 distribution groups and members each evening.

    Is it possible to use PowerShell to carry out the following in bulk:

    1. Select a certain amount of DLs to work on at a time say 50 to 100?
    2. Rename the existing to something like ‘name_old’ (to avoid name clash in the cloud when synchronised)
    3. Create the distribution lists with the same name and users in the cloud from the csv file?

    Many Thanks

  48. Hi Satheshwaran , thanks you for the good script,i run the script and sucessfully take the report.

    i need one more field add this script “Group Owner (Managed By)” of each distribution list can you please help me to add the same in script

    Many Thanks

  49. Hello Satheshwaran,

    Thank you for the great script. When I run the script, the output for the field for the Distribution Group Managers has the following value: System.Collections.ArrayList . I ran the line of code that generates the output for the field and it returns the same result. Have you seen that problem before?

    $managers = $Dg | Select @{Name=’DistributionGroupManagers’;Expression={[string]::join(“;”, ($_.Managedby))}}



  50. Hello Satheshwaran,

    We want to migrate all our Distribution list from on-prem Exchange to O365. Currently, we have a hybrid environment only distribution groups are pending to migrate the cloud. after DL migration we will be going to shut down the On-prem exchange server. Please let me know how we can migrate the DL with users in the Cloud.

  51. Thanks for sharing. Try this script for more detailed distribution group membership report.

  52. how do i need to run the script for list of groups for getting group members?.

  53. I can just change -resultsize unlimited to a specific OU, but it would be nice if you could include this as a choice in the task menu.

Leave a Reply

Your email address will not be published.