Member_2_3718378
asked on
Save a List of All Members in All Distribution Lists
One of our managers has asked for a list of all distribution lists, and the members of each one. I'm barely familiar with Powershell, so this is definitely beyond my abilities. Can anyone help me out?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the delay in responding.
I've created a script (see snippet below) that does a pretty good initial job. However, there's two problems... first, the start of the generated CSV file doesn't make sense to me:
========================== ========== ========== ========== ===
#TYPE System.Management.Automati on.PSCusto mObject
Name
"Joe Hartegu"
"Rob Flanes"
"Beth Forhill"
DistributionList-A
"Roger Sykes"
========================== ========== ========== ========== ===
Basically, it's listing a bunch of users before it shows me anything about the first distribution list. The second (smaller) problem is that there's no space between the last member in a DL and the next DL's name. Is there a way to add a newline/breakspace or two above each distribution list's name, just to help visually distinguish?
I've created a script (see snippet below) that does a pretty good initial job. However, there's two problems... first, the start of the generated CSV file doesn't make sense to me:
==========================
#TYPE System.Management.Automati
Name
"Joe Hartegu"
"Rob Flanes"
"Beth Forhill"
DistributionList-A
"Roger Sykes"
==========================
Basically, it's listing a bunch of users before it shows me anything about the first distribution list. The second (smaller) problem is that there's no space between the last member in a DL and the next DL's name. Is there a way to add a newline/breakspace or two above each distribution list's name, just to help visually distinguish?
Get-DistributionGroup | %{
Write-Host $_.Name
Write-Output $(Get-DistributionGroupMember $_.DistinguishedName | Select-Object Name)
} | Export-CSV "somefile.csv"
Sure, lets see if we can't make it pretty :)
What would you like to see in there? Just names? or Names and Distinguished Names? Or Descriptions or Job Titles? etc etc
Chris
ASKER
UPDATE: I found a blog that explained how to do it ( http://gnawgnu.blogspot.com/2007_08_01_archive.html ). Thank you for setting me on the right path... searching for information about Get-DistributionGroupMembe r was what let me to it.
Not bad :) I just dropped that method because didn't like the flexibility. I'll finish off mine and you can have a play with it if you like, or just carry on with that if it does what you need :)
Chris
Oh and....
DoSomething | Export-CSV "somefile.csv"
Is probably your best shot for writing it out to a file neatly.
Chris