Translate

Tuesday, March 27, 2012

PowerShell - Get Exchange Distribution Group Information

Today I was asked to create a list of our Exchange distribution groups showing the name of the group, list owner, and the notes field. Here is the script I used. The Get-Group PowerShell command is used to get the notes field. Output is sent to a csv file.

# Initialize array
$totalObj = @()

# Retrieve all DGs
$temp = Get-DistributionGroup -ResultSize Unlimited | select-Object name, managedby, @{n="Notes";e={(Get-Group $_).Notes}} |

# Loop through all distribution groups
ForEach-Object {

  # Create instance of object of type .NET
  $obj = New-Object System.Object

  # Add the name of the DG to the object
  #if ($i -eq 0) {
   $obj | Add-Member -MemberType NoteProperty -Value $_.name -Name 'Distribution Group' -Force
  #}

  # Add list owner of the DG to the object
  $obj | Add-Member -MemberType NoteProperty -Value $_.managedby -Name 'DG Manager' -Force 

  # Add notes of the DG to the object
  $obj | Add-Member -MemberType NoteProperty -Value $_.Notes -Name 'Description' -Force 
  
  # Add the object to the array
  $totalObj += $obj

}

# Pipe output to .csv file
$totalObj | Export-Csv c:\exchangescripts\ListMembers3-2012man.csv

2 comments:

  1. Thank you so much.....worked perfectly!

    ReplyDelete
  2. I was also asked the same and I was happy happy to find your script, but I am still not able to get the Note's field to export. Any other suggestions? Thanks! Eydie

    ReplyDelete

Thank you for commenting!