Showing posts with label export distribution list members from active directory to excel. Show all posts
Showing posts with label export distribution list members from active directory to excel. Show all posts

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, members and owners 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..