Get Local Security Groups and their Members from Remote Computers.
This was modified from Wright47’s 07 May 2009 12:58 AM post, and Ying Li’s post from 8/31/2007
- #You'll need admin perms on all the servers to run this...
- Write-Host "ComputerName in White, then Local Groups in Green, Local Groups' Members in White"
- #This feeds the script a list of server names (ServerList.txt, placed in the same directory)
- #for which I want the Local Groups and all those groups' Members.
- $x = Get-Content ServerList.txt
- # this feeds each servername, one by one, into the process...
- foreach ($j in $x) {
- #The server name becomes variable $strComputer
- $strComputer = "$j"
- #The Server name then becomes the variable $strComputer, and its name
- #is printed out in all CAPS
- $computer = [ADSI]("WinNT://" + $strComputer + ",computer")
- $g = $computer.name.ToString()
- $g.ToUpper(); " "
- #The local security groups on the Server is then found,
- #and fed to the array $a
- $group = $computer.psbase.children | where{$_.psbase.schemaclassname -eq "group"}
- $a = @()
- foreach ($member in $group.psbase.syncroot)
- {$a += $member.name }
- #Each Local Group Member is then printed (in white,and with a space) underneath its Group's name
- #(Group name printed in green)
- foreach ($i in $a) {
- $group =[ADSI]"WinNT://$j/$i"
- Write-Host "$i" -fore green
- $members = @($group.psbase.Invoke("Members"))
- $members | foreach { Write-Host " ",$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
- }
- Write-host " "
- Write-host " "
- Write-host " "
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository