Disable Local Administrator account for multiple servers
$list = Import-CSV "C:\Scripts\Serverslist.csv" #change location of your file
foreach($servers in $list) {
try{
$computer = $servers.ServerName
$User = [ADSI]"WinNT://$computer/Administrator,user"
$User.AccountDisabled = $True
$User.SetInfo()
Write-Host "Administrator Account has been disabled on $computer Succesfully" -ForegroundColor "Green" -BackgroundColor "Black"
}
catch
{
Write-Host "Unable to reach server $computer" -ForegroundColor "Yellow" -BackgroundColor "Red"
}
}
$list = Import-CSV "C:\Scripts\Serverslist.csv" #change location of your file
foreach($servers in $list) {
try{
$computer = $servers.ServerName
$User = [ADSI]"WinNT://$computer/Administrator,user"
$User.AccountDisabled = $True
$User.SetInfo()
Write-Host "Administrator Account has been disabled on $computer Succesfully" -ForegroundColor "Green" -BackgroundColor "Black"
}
catch
{
Write-Host "Unable to reach server $computer" -ForegroundColor "Yellow" -BackgroundColor "Red"
}
}
No comments:
Post a Comment