Distribution List members report

This post is also available in: Polish

When you want to have report of your distribution groups with information who belong to these groups you can create PowerShell script to write each group to separate file with all members.

First you need to decide if you wan to specify distribution groups (like in file) or you want to get all distribution groups.

To get groups from file use:

$DLs = get-content d:\scripts\DLgroups.txt

to get all distribution groups use:

$DLs = get-distributiongroup -resultsize unlimited | select name
foreach ($dl in $DLs){
 if (!(get-distributiongroup $dl)){
 Write-Host "$dl is not valid"
 } else {
 $dl_tmp = get-distributiongroup $dl
 $outfile = "d:\scripts\DL_$($dl_tmp.name)_.txt"
 Add-Content $outfile get-Date
 Add-Content $outfile "$($dl_tmp.name) $($dl_tmp.SMTPAddress)" 
 Add-Content $outfile "Members"
 Add-Content $outfile "Alias;Displayname;Company;Title;emailaddress"
 $members = get-distributiongroupmember $($dl_tmp.alias)

 foreach ($member in $members){
 $user = $member.alias + ";" + $member.DisplayName + ";" + $member.Company + ";" + $member.Title + ";" + $member.primarysmtpaddress.local + "@" + $member.Primarysmtpaddress.domain 
 Add-Content $outfile $user

With this short script you will get one file for each distribution group with members of this group.



Print Friendly
Tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>