Link to home
Start Free TrialLog in
Avatar of Newguy 123
Newguy 123

asked on

Export Distribution Group members into a readable csv file

Hello Experts, I have the following PS script to export DistributionGroup members into a csv file. This export names the first column 'GroupName' and second column 'Members'. it places all members of the Distribution group in one cell of the 'members' column separated by a semi-colon.

How can I make it so that each different group member gets placed into a new row with 'groupname' and 'member'. I would basically like to have each 'members' cell contain only one user, otherwise I have to fiddle around with Excel to make it the way i would like.

$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 "path\export.csv" -NoTypeInformation -Encoding UTF8 

Open in new window


Please let me know. Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial