?
Solved

Save a List of All Members in All Distribution Lists

Posted on 2009-05-12
6
Medium Priority
?
509 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 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 71

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
Ransomware Attacks Keeping You Up at Night?

Will your organization be ransomware's next victim?  The good news is that these attacks are predicable and therefore preventable. Learn more about how you can  stop a ransomware attacks before encryption takes place with our Ransomware Prevention Kit!

 
LVL 71

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 71

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

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

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 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