Monday , January 23 2017

How to Export all distribution Group and All members of it (Exchange 2007 & Exchange 2010 & Exchange 2013)

In some situations we have to Export all the Distribution group 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. Pipe line won’t work in this case.

NEW

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

I have wrote a script which will make Exchange Administrators life Easy to export distribution group and its members.

.Requires -version 2 – Runs in Exchange Management 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

image

Run it as above

Output of CSV file look 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 its unrestricted.

To Get Execution Policy Status

Get-ExecutionPolicy

image

$UserCredential = Get-Credential

image

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

image

Import-PSSession $Session

Now Run the Script – It should work.

About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Exchange Server MVP , Publisher of CareExchange.in Supporting/Deploying/Designing Microsoft Exchange for some years. Extensive experience on Microsoft Technologies.

Check Also

Mailbox Replication Service was unable to connect to the remote server

Office 365 Mailbox Migration Error – The migration encountered an error The Mailbox Replication Service ...

84 comments

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

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

  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.

    • 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
        Managedby
        Members
        members count
        Mailcontacts
        RequireSenderAuthenticationEnabled
        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.

    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

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

  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
    tatement.
    At C:\DG\DistributionGroupMemberReport.ps1:13 char:47
    + [PS] C:\DG>.\DistributionGroupMemberReport.ps1 <<<<"

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

  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?

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

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

    Cheers
    James

  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?

    Regards,
    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.

    Regards,
    Saravanan

  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.

    Regards
    Sivakumar

  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.

    Regards,
    Harmeet Chauhan

  28. Just use this, easier way

    CURTIS

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

    Thank you,

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

    Greetings!

  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

    Niels

  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?

    Thanks!

  37. Did you ever implement expansion of nested groups?

    Thanks!

Leave a Reply

Your email address will not be published.