Solved

Save a List of All Members in All Distribution Lists

Posted on 2009-05-12
6
505 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 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 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 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