August 22

How to use Powershell to Export All Distribution Groups and Members to CSV

Create a temp fold at c:\ called c:\temp and run the following script


$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:\temp\Distribution-Group-and-Members.csv" -NoTypeInformation -Encoding UTF8


Posted August 22, 2023 by Ray in category "Exchange", "Microsoft 365

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.