Link to home
Create AccountLog in
Avatar of Christopher Horridge
Christopher HorridgeFlag for United States of America

asked on

How to Dump Distribution List Membership in to an Excel sheet

I have the following script which I am using to dump out Distribution List, Owner, and PrimarySMtp which exports it out into a CSV file:

Get-DistributionGroup | Select-object Name,@{label="ManagedBy";expression={[string]($_.managedby | foreach {$_.tostring().split("/")[-1]})}},Primarysmtpaddress | Export-Csv path

What I am wondering is if anyone knows what command to insert into the above script to get the group memebership for the DL's?
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

You can use the get-distributiongroupmember command.
Avatar of Christopher Horridge

ASKER

You cannot pipe the get-distributiongroupmember, it will error out telling you that you are not allowed to do it.
get-distributiongroupmember groupname | export-csv c:\list.csv
The above listed script will pipe out all of our DL's and so I want the groups to be in line with each one of the DL's which the above will give me the group membership, but for only that one group; I need group membership for 400+ groups so I don't want to do the above 400+ times :)  Thank you though.
How about this?

Get-DistributionGroup  | foreach{
$name = $_.name
$managedby =$_.managedby
$primarysmtpaddress = $_.primarysmtpaddress
"Distribution group:$name, ManagedBY:$managedby, Email:$primarysmtpaddress">>c:\email.txt
Get-DistributionGroupMember $name | select-object name >> c:\email.txt
"" >>c:\email.txt
}
here is the error you get when trying to do get-distributiongroup and get-distributiongroupmembers:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
ASKER CERTIFIED SOLUTION
Avatar of Joseph Daly
Joseph Daly
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account