Don’t do that: There is the possibility to to get all the groups (nested) a user is memberOf with the cmdlet “Get-QADuser” of Quest (now DELL).
(Get-QADUser -Identity SamAccountName).AllMemberOf
Do that: The above code works well, but it requires a 3rd party Snapin, there is a native one-liner way to receive “AllMemberOf” for a user.
Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($distinguishedName))"