我一直在嘗試使用此腳本來重置所有本地管理員密碼,如果服務器列表中只有一個服務器,腳本運行得非常好,但是,如果有多個服務器,它會拋出錯誤爲 -整個域的本地管理員密碼更改
服務器x「無法找到用戶名。」 檢索成員「SetInfo」時發生以下異常:「無法找到用戶n ame」。 在C:\用戶\ v7t7adm \桌面\ localadmin.ps1:18字符:15 + $ user.SetInfo < < < <() + CategoryInfo:NotSpecified:(:) [],ExtendedTypeSystemExceptio Ñ + FullyQualifiedErrorId: CatchFromBaseGetMember
這裏是我創建的腳本 -
$computers = Get-Content servers.txt
"Name`tStatus" | Out-File -FilePath C:\users\v7t7adm\desktop\results.csv
$user = "KArthur"
$password = "Pol!sh90&8"
foreach($server in $computers)
{
try{
$user = [adsi]"WinNT://$server/$user,user"
$user.SetPassword($password)
"$server`tSuccess"
"$server`tSuccess" | Out-File -FilePath C:\users\v7t7adm\desktop\results.csv -Append
}
catch{
"$server`t" + $_.Exception.Message.ToString().Split(":")[1].Replace("`n","")
"$server`t" + $_.Exception.Message.ToString().Split(":")[1].Replace("`n","") | Out-File -FilePath C:\users\v7t7adm\desktop\results.csv -Append
}
$user.SetInfo()
}
這是一個非常糟糕的主意硬編碼在腳本中明文密碼。 (將它發佈到互聯網上也是不好的。) –