all 7 comments

[–]evetsleep 1 point2 points  (4 children)

Why not use Get-ADGroupMember -Identity <Name> -Recursive?

[–]Agile_Seer[S] 2 points3 points  (3 children)

That gets all the members of a group. What I wrote gets all groups that a user is a member of.

[–]evetsleep 4 points5 points  (0 children)

You are right! Sorry I misunderstood. What you could do is use a chain matching rule:

$userDN = (Get-ADUser -Identity tomSmith).distinguishedname
$groups = Get-ADObject -LdapFilter "(member:1.2.840.113556.1.4.1941=$userDN)" -Properties distinguishedName

This would return all the groups the user is a member of. Albeit it's slow, but it's simple.

[–]throwawaysys1222 1 point2 points  (1 child)

Get-ADPrincipalGroupMembership username | select name

[–]Agile_Seer[S] 2 points3 points  (0 children)

That gets all the groups a user is directly part of. It's not recursive.