Tuesday, 12 May 2015

Quick and Easy Check For Nested Groups

I sometimes find myself needing to check if a group contains any other nested groups.  I don’t necessarily need to know who the members are of each nested group, I just want to know if it contains other groups and what those groups are named.  You can use this quick one liner to get a list of any groups who belong to the group specified, in this case Citrix_Users

001
Get-ADGroupMember Citrix_Users | where {$_.objectClass -ne "user"} | select -ExpandProperty Name

Each AD object has an objectClass property associated with it.  All this one-liner does is get each member of the specified group, and if its attribute is not user, display the group name.  Depending on how frequently you used this, you could add a parameter for the group name and even add it as a function to your PowerShell profile so that it’s loaded automatically each time you run PowerShell.

No comments:

Post a Comment