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
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
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
Get-ExecutionPolicy
Connect-ExchangeOnline
Now Run the Script – It should work.
Git Public Repository Link –
azure365pro/DistributionGroupMemberReport (github.com)
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
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.
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
Run in Exchange Management Shell. Check you have proper permissions
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.
Try Repro the Commands in the script on your environment. It cannot be the case.
Excellent , Thank you
Welcome Jeff !
Can you please send me the command to import approx 400 users to a DL through a csv file.
Import-CSV C:Filename.csv | Foreach{Add-DistributionGroupmember DGNAME -Member $_.Members}
CSV file topic should be Members. Which has the list of 400 Alias
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}
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
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
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. ?
Awesome script. Thank you!
Thank you Mahmoud
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)
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 <<<<"
Right Click , Run as administrator , and give a try.
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
Is there a possibility to (only) read out the hidden D-groups?
Thanks a lot!
Replace Get-Distribution Group with Get-DistributionGroup | Where-Object{$_.HiddenFromAddresslistsEnabled -eq “True”}
It should export hidden ones
Thanks
Great script, sure saved me a lot of time. Thank you!
You are most welcome Phil
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 ?
i Have the loop. Not to have that cotent .Returning 0.
so u can custom the for loop
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?
nevermind, solved it 🙂
$output | Export-csv -Path $CSVfile -encoding “unicode”
Thanks for sharing petr
Fixed now . thank you
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
Awesome script, makes keeping lists in check alot easier – thanks
would it possible to output the distribution lists email address as well?
Cheers
James
Added now . Check the Gallery . thank you
Really good Script.
what can i do so the script also exports the OU name as well.
Added now . Check the Gallery . thank you
Very good script! Did exactly what I needed. Thank you!!!!!!!
Thank you
Hello Team ,
How to find out Dl member count. ( not list i want only member count )
Is there any way ?
Yes . (Get-distributiongroupmember “dgname”).count
Loop it . you extract it .
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.?
Check for distribution group attributes. you can find a way.
Hi!
Is there any command to export the distribution groups in exchange 2003?
Regards,
Arun Prasath M
No power shell in 2003 , YOu can try taking dumps. csvde dumps.
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
Can you please reply on this???
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
There is no ready made script available. as of now.
i have 100 DL and i wanted to find the owner of these DL’s. how can i do it
You can customize the script.
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?
i will look forward to add that feature soon.
Hi Satesh,
Waiting for modification where we can see nested DLs as well.
I will add them soon.
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,
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
Just use this, easier way
CURTIS
Where does it show the member of the DL?
Thank you,
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.
Regards
Rajen
Which version of Exchange you are running ?
Email to info @ Careexchange.in to check Further.
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.
Saved me many hours of doing it manually. Your script also helps to find duplicate errors. Great job.
There is certainly a lot to find out about this
subject. I love all the points you made.
Hello Satheshwaran Manoharan,
ist it possible to rewrite some lines in this script to get the same resulst just fpr securitygroups?
Greetings!
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
Am on it. Let me check.
I have updated the Article – Please follow the same steps .
Ran it myself on Office 365. It works fine.
Hi Can you please send me the script please Thank you
http://gallery.technet.microsoft.com/Export-all-distribution-707c27eb
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.
is it same domain ?
Did you ever implement expansion of nested groups?
Thanks!
Did you ever implement expansion of nested groups?
Thanks!
Yes, It will show Group 1 has members NestedGroup1.
and nested group1 members in the same list below separately.
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
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.
Well I really enjoyed studying it. This subject provided
by you is very constructive for good planning.
Hi Sathesh, can it also list the access rights each of the member hold on the respective distribution group?
No.
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
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
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
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.
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?
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
Needs a lot of PowerShell work. I have a feeling that Microsoft will release a feature soon. To Convert them in Cloud only. Its needed my many community members.
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
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
Yep, I get the same when I execute the script.
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.
how do i need to run the script for list of groups for getting group members?.
Regards,
ShabberShaik
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