Recursively Listing Security Group Members with PowerShell
August 20, 2009 2 Comments
It seems like a favorite request of auditors is one for lists of all members of a set of local or domain groups that are associated with a resource that is being audited, and these requests typically stipulate that all members of nested groups must be listed as well (i.e. full recursion). I used to use a VBS script to perform this functionality, but I’ve recently rewritten it in PowerShell. The script accepts a group name (either local or domain) as well as a recursion depth as command line arguments and outputs a list of all group members to a text file.
The method used to retrieve the group members is:
$Group= [ADSI]”WinNT://$GroupName,group”
$Members = @($Group.psbase.Invoke(“Members”))
With that, it’s just a matter of configuring a function that accepts a group name as an input parameter, outputs the members, and loops through the member groups until the defined recursion depth is reached.
The script can be downloaded here. And the output looks like:
The script could be easily modified to accept a text file with a list of group or server names as in input, or modified to output the results in HTML instead of plain text.
Pingback
http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!519.entry
Pingback: Recursively Listing Security Group Members with PowerShell, Version 2 « Operating-Quadrant