Monday, 6 June 2016

Command to export DLs Members List in Office365 Server?

Or, PowerShell command to exports list of DLs along with members in Office365 server.
Or, PowerShell command to export all DLs and members list in Office365 Server.

Please run the below command on Office365 PowerShell windows to get the list of all DLs and It's members.
------------------------------------------------------------------------------------------------------------------------------
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$Owner = (Get-DistributionGroup -Identity $group).ManagedBy
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
        If($members) {
              $members=$members + ";" + $_.Name
           } Else {
              $members=$_.Name
           }
  }
New-Object -TypeName PSObject -Property @{
      GroupName = $group
      Members = $members
     Owner = $Owner
     }

} | Export-CSV "D:\Distribution-Group-Members3.csv" -NoTypeInformation -Encoding UTF8
------------------------------------------------------------------------------------------------------------------------------
Cheers..

No comments:

Post a Comment