I have been searching for a way to run a powershell script that does not call another text file but that simpley will add a User account and a Domain Group to the Lcoal Administrators group. I have tried the below, and it says it adds the test user 'Dummy' but when i actually check the local Administrators group, the "Dummy" account is not there.
# if your user name is whatever\test
$domain = "DomainName"
$strComputer = "Localhost"
$username = "Dummy"
$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}
ListAdministrators
# 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
$Group.Remove("WinNT://" + $domain + "/" + $username)
ListAdministrators
David Baur