Thursday, August 5, 2010

Windows Local Admin Maintenance

local admin group maintenance:

# if your user name is whatever\test

$Server = ""

Foreach($strComputer in $Server)
{
$domain = "blah"
$username = "Fbloke"
$break = "=============="

$computer = [ADSI]("WinNT://" + $strComputer + ",computer")
$computer.name

$Group = $computer.psbase.children.find("administrators")
$Group.name

# This will list what’s currently in Administrator Group so you can verify the result

function ListAdministrators

{$members= $Group.psbase.invoke("Members") | %{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$members}
$strComputer
ListAdministrators
$break

# Even though we are adding the AD account but we add it to local computer and so we will need to use WinNT: provider

$Group.Add("WinNT://" + $domain + "/" + $username)

ListAdministrators
$break

# then the option to remove if needed
#$Group.Remove("WinNT://" + $domain + "/" + $username)

#ListAdministrators
}

No comments: