MilesLogan
asked on
Remove a domain user from local Administrators group
HI EE
Does anyone have a script they can share that will remove user objects from the local Administrators group on a Windows server(s)?
Ideally I would like to enter the server names to a text file and the SamAccountnames to another text file.
$ErrorActionPreference = "Stop"
GC Servers.txt | %{
$Serv = $_
$domain="MyDomain"
$group = "GroupName"
Try {
([adsi]"WinNT://$Serv/Admi nistrators ,group").R emove("Win NT://$doma in/$group, group")
"" | Select @{N="Server";e={$Serv}},@{ N="Status" ;e={"Succe ss"}}
}
Catch{
"" | Select @{N="Server";e={$Serv}},@{ N="Status" ;e={"Faile d"}}
}
}
Does anyone have a script they can share that will remove user objects from the local Administrators group on a Windows server(s)?
Ideally I would like to enter the server names to a text file and the SamAccountnames to another text file.
$ErrorActionPreference = "Stop"
GC Servers.txt | %{
$Serv = $_
$domain="MyDomain"
$group = "GroupName"
Try {
([adsi]"WinNT://$Serv/Admi
"" | Select @{N="Server";e={$Serv}},@{
}
Catch{
"" | Select @{N="Server";e={$Serv}},@{
}
}
ASKER
Hi Foxluv , I cant configure a GPP on these servers why I need to remove them manually.. thanks for the tip .
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the tips , will give it a try .
ASKER
Thanks ..
The author has thanked for the participation and seems to be content with the answers given.
ref link: http://www.grouppolicy.biz/2010/01/how-to-use-group-policy-preferences-to-secure-local-administrator-groups/
create your gpp and apply it to the OU or OUs with your servers.