NestedGroups, again, improved…

Being able to retrieve nested groupmembership for users was nice. But I also wanted to be able to retrieve this for groups. In researching the possibilities PowerShell has to offer I’ve found some more remarkable techniques that display the flexibility of PowerShell.
And as such, I have rewritten my Get-NestedGroups function, again. And I also thought I’d rename it to Get-ADGroupMembership.

The function accepts three different input types: String, ADUser or ADGroup. This input type is automatically detected and processed according to its type (more on this technique in a later post).
Any input type other than ADUser or ADGroup will be cast as String. A switch differentiates between users and groups. Note that when the switch is used the input type will always be cast as String, even if it is of the type ADUser or ADGroup.

In order to prevent errors when run for the first time I had to load the ActiveDirectory assembly first. So now, if the ActiveDirectory assembly doesn’t exist, then the function will not be declared and remain unavailable. Note that loading the ActiveDirectory assembly does not load the ActiveDirectory module.

Here is the full Cmdlet:


Tagged , , . Bookmark the permalink.

Comments are closed.