18 C
Dubai
Sunday, December 22, 2024

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.

NEW

****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***

DisplayName
Alias
RecipientType
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

image

Download the Script

How to use this Script for Office 365 – 

Local desktop. PowerShell – Run as Administrator

image

Make Sure your Execution Policy is set to RemoteSigned or Unrestricted

Set-ExecutionPolicy RemoteSigned

my Case is unrestricted.

To Get Execution Policy Status

Get-ExecutionPolicy

image

Connect-ExchangeOnline

Now Run the Script – It should work.

Git Public Repository Link –

azure365pro/DistributionGroupMemberReport (github.com)

 

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Award-winning Technology Leader with a wealth of experience running large teams and diversified industry exposure in cloud computing. From shipping lines to rolling stocks.In-depth expertise in driving cloud adoption strategies and modernizing systems to cloud native. Specialized in Microsoft Cloud, DevOps, and Microsoft 365 Stack and conducted numerous successful projects worldwide. Also, Acting as a Technical Advisor for various start-ups.

Related Articles

103 COMMENTS

  1. 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. 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

      • 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. 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.
    Ben

    • 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}

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

      • 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
        Managedby
        Members
        members count
        Mailcontacts
        RequireSenderAuthenticationEnabled
        AcceptMessagesOnlyFromSendersOrMembers (AcceptMessagesOnlyFrom ; AcceptMessagesOnlyFromDLMembers)
        Last Modified Time

  5. 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.

    But
    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?

    • 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

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

    • Hey Micogo,

      Can you run Get-DistributionGroup and Get-distributiongroupmember

      make sure those cmdlets work fine. ?

  7. 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)

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

      • I’ve been having the same problem:

        ‘C:\DG>.\DistributionGroupMemberReport.ps1? in expression or s
        tatement.
        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.

        • Can you run – Get-distributiongroup

          Get-distributiongroupmember

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

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

      It should export hidden ones

      Thanks

  9. 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 ?

  10. 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?

  11. 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?

    • 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

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

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

    Cheers
    James

  13. 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.?

  14. Hi Satheshwaran,

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

    Regards,
    Saravanan

  15. 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.

    Regards
    Sivakumar

  16. 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?

  17. 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.

      • 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.

        Regards
        Rajen

  18. 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.

  19. Hello Satheshwaran Manoharan,

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

    Greetings!

  20. 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

    Niels

  21. 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.

  22. 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.

    Regards
    Amreesh Kumar

  23. 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.

  24. 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

    • 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

  25. 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.

  26. 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?

  27. 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

  28. 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

  29. 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))}}

    Thanks,

    Roger

  30. 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.

  31. 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.
    Thanks
    Christian

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?