Forum Discussion
Baron164
Jul 14, 2022Brass Contributor
How can I add group membership information to this csv export?
I am currently exporting a list of user accounts which have uidNumbers. So far so good, but now I need to also include in this export, group information. Specifically the gidNumber for each group eve...
- Jul 19, 2022
$fullReport=@() $AllUsers=Get-ADUser -Filter "uidNumber -ge 0" -Properties Name,givenName,sn,uidNumber,userPrincipalName foreach ($singleuser in $AllUsers){ $Report=[PSCustomObject]@{ Name = $singleuser.Name givenName=$singleuser.GivenName sn=$singleuser.sn uidNumber=$singleuser.uidNumber userPrincipalName=$singleuser.userPrincipalName } $AllGroups=Get-ADPrincipalGroupMembership $singleuser.SamAccountName for ($i = 0; $i -lt $AllGroups.name.count; $i++) { $GroupGid=Get-ADGroup -Properties gidNumber -Identity $AllGroups[$i].SamAccountName $Report | Add-Member -NotePropertyName "Group$i" -NotePropertyValue $GroupGid.gidNumber } $fullReport+=$Report }
Let me know 🙂
Baron164
Jul 18, 2022Brass Contributor
So far so good, the only issue I have is that it's showing the group names instead of the gidNumber attribute. I tried changing the $AllGroups.name to $AllGroups.gidNumber but that does not work.
farismalaeb
Jul 18, 2022Iron Contributor
Just to confirm, So you dont need the group name, you need to have the gidNumber
So the output looks like
Name : vdi2
givenName : vdi2
sn : 3
uidNumber : 1
userPrincipalName : email address removed for privacy reasons
Group0 : 1231231
Group1 : 123134234534
yes?
So the output looks like
Name : vdi2
givenName : vdi2
sn : 3
uidNumber : 1
userPrincipalName : email address removed for privacy reasons
Group0 : 1231231
Group1 : 123134234534
yes?
- Baron164Jul 18, 2022Brass ContributorYes, that is correct.
- farismalaebJul 19, 2022Iron Contributor
$fullReport=@() $AllUsers=Get-ADUser -Filter "uidNumber -ge 0" -Properties Name,givenName,sn,uidNumber,userPrincipalName foreach ($singleuser in $AllUsers){ $Report=[PSCustomObject]@{ Name = $singleuser.Name givenName=$singleuser.GivenName sn=$singleuser.sn uidNumber=$singleuser.uidNumber userPrincipalName=$singleuser.userPrincipalName } $AllGroups=Get-ADPrincipalGroupMembership $singleuser.SamAccountName for ($i = 0; $i -lt $AllGroups.name.count; $i++) { $GroupGid=Get-ADGroup -Properties gidNumber -Identity $AllGroups[$i].SamAccountName $Report | Add-Member -NotePropertyName "Group$i" -NotePropertyValue $GroupGid.gidNumber } $fullReport+=$Report }
Let me know 🙂
- Baron164Jul 19, 2022Brass ContributorPerfect, thank you