Solved

Save a List of All Members in All Distribution Lists

Posted on 2009-05-12
6
484 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Synchronize a new Active Directory domain with an existing Office 365 tenant
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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