PowerShell Script to check the Security Group added to the Administrator list

Posted on: January 6, 2014


Again after longtime I am writing here 🙂

Earlier today I was having bunch of Servers on which I was not sure if I have access to all of them. I wanted to know the server list on which my network ID is added to the Local Administrator Group. 🙂

I came up with below powershell script which help us to find out if the network ID has been added to the administrator list or not (Mainly for Remoting into the Server :))

$Servers = Get-Content C:\Servers.txt
Foreach($strComputer in $Servers)
$computer = [ADSI](”WinNT://” + $strComputer + “,computer”)
$Group = $computer.psbase.children.find(”Administrators”)
[string]$members = ($Group.psbase.invoke(”Members”) | %{$_.GetType().InvokeMember(”Adspath”, ‘GetProperty’, $null, $_, $null)}) -replace (‘WinNT://DOMAIN/’ + $server + ‘/’), ” -replace (‘WinNT://DOMAIN/’, ‘DOMAIN\’) -replace (‘WinNT://’, ”)
$m = $members.Replace(” “,”,”)
$k = $m.Replace(“/”,”\”)
[array]$l = $k -split “,”
if(($l | %{$_}) -eq “\User1”)
Write-Host “You have admin rights on $StrComputer”
Write-Host “You don’t have admin rights on $StrComputer”
Write-Host “$Strcomputer has an exception”

The server list will go in C:\Servers.txt\User1 — is the account name which you want to validate.

I hope this helps.


-Prashant Girennavar.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: