Export Distribution List Members to CSV using Powershell

We can get Distribution list members by using the Exchange cmdlet Get-DistributionGroupMember in Powershell and export Distribution list members to CSV file using Powershell cmdlet Export-CSV.

Get Distribution Group members

Use the following Powershell command to list Distribution list members.

Get-DistributionGroupMember -Identity <Group-Name>

Export Members of a single Distribution Group to CSV

The following Powershell script gets members of a given distribution group and exports output to CSV file. Replace the distribution group name “TestDG” with your own group name in the below script.

$DGName = "TestDG"
Get-DistributionGroupMember -Identity $DGName | Select Name, PrimarySMTPAddress |
Export-CSV "C:\Distribution-List-Members.csv" -NoTypeInformation -Encoding UTF8

Export All Distribution Groups and Members to CSV

We can list all the distribution groups using Exchange cmdlet Get-DistributionGroup and get its members by passing group name into Get-DistributionGroupMember cmdlet. The following Powershell script gets all the distribution groups and its members and exports group names and members to CSV file.

$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
        If($members) {
              $members=$members + ";" + $_.Name
           } Else {
              $members=$_.Name
           }
  }
New-Object -TypeName PSObject -Property @{
      GroupName = $group
      Members = $members
     }
} | Export-CSV "C:\Distribution-Group-Members.csv" -NoTypeInformation -Encoding UTF8
Advertisement

12 thoughts on “Export Distribution List Members to CSV using Powershell”

  1. Thank you. This worked like a charm, although I had to use GUID instead of Name for the Idendity, and EmailAddress for the export. Something to do with how Intermedia works.

    Reply
  2. Hello, I have an excel with two columns,
    Column A -> Group-Name
    Column B -> [email protected]
    There are 38 rows one for each Group-Name
    I want to export all the members of each Group-Name in a excel (could be also a CSV) that has in
    Column A -> Group-Name
    Columb B -> member’s mail
    The expected is that there will be more rows with equal Group-Name.
    How I can implement?
    I suppose that $Groups = Get-DistributionGroup should be modified in a source file, maybe a CSV with a single column having in position A1 a label i.e. DLNAME

    Reply
  3. Hello Morgan, Could you please help me in exporting Group members of a Distribution Group which is created in O365.

    Reply
  4. Hi,

    what would I need to do to include a column for members email addresses so its not just their email addresses?

    Thanks

    Reply
    • You can read the below post to export distribution group members with member details such as DisplayName, Name and PrimarySMTPAddress.

      https://morgantechspace.com/2018/04/export-office-365-distribution-group-members-csv-powershell.html

      $Result=@()
      $groups = Get-DistributionGroup -ResultSize Unlimited
      $totalmbx = $groups.Count
      $i = 1
      $groups | ForEach-Object {
      Write-Progress -activity "Processing $_.DisplayName" -status "$i out of $totalmbx completed"
      $group = $_
      Get-DistributionGroupMember -Identity $group.Name -ResultSize Unlimited | ForEach-Object {
      $member = $_
      $Result += New-Object PSObject -property @{
      GroupName = $group.DisplayName
      Member = $member.Name
      EmailAddress = $member.PrimarySMTPAddress
      RecipientType= $member.RecipientType
      }}
      $i++
      }
      $Result | Export-CSV "C:\All-Distribution-Group-Members.csv" -NoTypeInformation -Encoding UTF8

      Reply

Leave a Comment