Is it possible to change the PS script below in two ways:
- The group members are now exported horizontally but I want all the users in 1 cell in the column beside the group name. We have a lot of groups and it is not readable this way.
- The path to the folders in the description field of the AD groups are not exported. I would like to have the content of the description field also exported in the column beside the group.
I would like to see this result, see the photo below please:
cls
$Groups = "Group1", "Group2", "Group3"
$results = foreach ($Group in $Groups) {
Get-ADGroupMember -Server contoso.com $group |
select SamAccountName, @{n='GroupName';e={$group}}, @{n='Description';e={(Get-ADGroup $group -Properties description).description}}
}
$results
$results | Export-csv C:\TEMP\GroupMemberShip.CSV -NoTypeInformation
With some minor changes to your original code, you could first gather the wanted info per group and before exporting to CSV, use
Group-Object
to merge the details.Something like:
Although I don't understand why you would like to have duplicate items in your output, you can do this like below