I'm trying to get an CSV Output from ADGroupMembers in ADGroups like this:
groupname,member1,member2,member3...
I use the following script:
Get-ADGroup -Filter * -SearchBase "OU=myou,OU=myou,DC=domain,DC=local" | group {$_.name} | % {
$group = $_.name
$member = (Get-ADGroupMember -Identity $group |
select @{n='Group';e={$group}}, @{n='Member';e={$_.Name}}) -join ','
'{0},{1}' -f $group,$member
} | Out-File 'out-file-try.csv'
Problem is: my Output shows no members:
Group1,,,,,,,,,,,,,,
Group2,,
Group3,,
Group4,,,,,,,,
Group5,,,,,,,,,,
Can anyone help?
Thanks a lot!