The Get-LocalGroupMembership function will query a single or multiple systems (to include remote) for a specified local group and its members. If members are a group (local or domain), the script will then begin to query all of those groups for members as well. To prevent the possibility of infinite recursion caused by parent groups being nested in the child groups, I ensure that if those groups come up, they are not queried again if already performed. Also, the recursion depth can be set to a specified number (-Depth parameter). By default, the -Depth parameter is set to 2147483647 ([int]::MaxValue).

This will run against stand-alone systems (not domain joined), but will throw an error stating that i cannot find the security context associated with Active Directory, which can be ignored.

Related Blog post: http://learn-powershell.net/2013/08/11/get-all-members-of-a-local-group-using-powershell/

 

Remember to dot source the script file to load the function into the current session.

 

PowerShell
Edit|Remove
. .\Get-LocalGroupMembership
 
PowerShell
Edit|Remove
Get-LocalGroupMembership -Computername Server1 -Group Administrators -Depth 5