Exchange 2007 DG Members
Hello,I am using that below shell command to get members from a DG:Get-DistributionGroupMember –identity “group name” | ft name, primarysmtpaddress | Export-CSV c:\members.csvI would need to extract all the Distribution groups with the members.It may be a simple thing to change but can not figure out what needs to be change.Note that I have a lot of distribution groups.Regards,Gregory
January 18th, 2010 11:53am
This works on my box. It is slightly changed from here: Powershell command to list all distribution groups and members of those groups
http://social.technet.microsoft.com/Forums/en/exchangesvradmin/thread/63ad55d1-1393-4533-8065-1d7cbd8657fa
# Initialize array with three fields:
# Distribution group, Members, Primary SMTP Address
$totalObj = @()
# Retrieve all DGs
$temp = Get-DistributionGroup -ResultSize Unlimited |
# Loop through all distribution groups
ForEach-Object {
# Add the members of the DG to an array
[array]$mem = Get-DistributionGroupMember -id $_
# Loop through the DG and assign each member name to the variable $member
for ($i = 0; $i -lt $mem.Count; $i++) {
$member = $mem[$i].name
$smtpAddress = $mem[$i].PrimarySmtpAddress
# Create instance of object of type .NET
$obj = New-Object System.Object
# Add the name of the DG to the object only the first time
if ($i -eq 0) {
$obj | Add-Member -MemberType NoteProperty -Value $_.Name -Name 'Distribution Group' -Force
}
# Add the member name to the object
$obj | Add-Member -MemberType NoteProperty -Value $member -Name 'Members' -Force -PassThru
# Add the member name to the object
$obj | Add-Member -MemberType NoteProperty -Value $smtpAddress -Name 'SMTP Address' -Force -PassThru
# Add the object to the array
$totalObj += $obj
}
}
# Pipe output to .csv file
$totalObj | Export-Csv -NoTypeInformation -Encoding 'Unicode' -Path c:\temp\ngtest.csv
MCTS: Messaging | MCSE: S+M | Small Business Specialist
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2010 1:09pm
Amazing Script!! as usual Jon-Alfred!!Thanks a milion.Graig
January 18th, 2010 3:46pm