Solved

Save a List of All Members in All Distribution Lists

Posted on 2009-05-12
6
475 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now