prashant1987

Archive for January 2014

HELLO’S,

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)
{
try
{
$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 “Contoso.com\User1”)
{
Write-Host “You have admin rights on $StrComputer”
}
Else
{
Write-Host “You don’t have admin rights on $StrComputer”
}
}
Catch
{
Write-Host “$Strcomputer has an exception”
}
}

The server list will go in C:\Servers.txt

Contoso.com\User1 — is the account name which you want to validate.

I hope this helps.

Thanks,

-Prashant Girennavar.