Solved

Save a List of All Members in All Distribution Lists

Posted on 2009-05-12
6
492 Views
Last Modified: 2012-05-06
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?
0
Comment
Question by:deathtospam
  • 4
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 24368329

How does he want it formatted?

Something like this is a good beginning:

Get-DistributionGroup | %{
  Write-Host $_.Name
  Write-Output $(Get-DistributionGroupMember $_.DistinguishedName | Select-Object Name)
}

That might need a spot of work, nothing to test on at the moment so it may have glaring errors. But these are your best bet:

Get-DistributionGroup
Get-DistributionGroupMember "<GroupName>"

Chris
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 24368624

Oh and....

DoSomething | Export-CSV "somefile.csv"

Is probably your best shot for writing it out to a file neatly.

Chris
0
 
LVL 9

Author Comment

by:deathtospam
ID: 24374903
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.Automation.PSCustomObject
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"

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 70

Expert Comment

by:Chris Dent
ID: 24374968

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
0
 
LVL 9

Author Comment

by:deathtospam
ID: 24375210
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-DistributionGroupMember was what let me to it.
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 24375258

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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question