私はこのスクリプトを使ってすべてのローカル管理者のパスワードをリセットしようとしていますが、サーバーリストにサーバーが1つしかないとスクリプトは完璧に動作します。エラーとして -ドメイン全体のローカル管理者パスワードの変更
サーバーx "ユーザー名が見つかりませんでした。 メンバ "SetInfo"の取得中に次の例外が発生しました: "ユーザーn が見つかりませんでした。 \ユーザー\ v7t7adm \デスクトップ\のlocaladmin.ps1:18文字:15 + $ user.SetInfo < < < <() + CategoryInfo:NotSpecified:(:) []、ExtendedTypeSystemExceptio N + FullyQualifiedErrorId:Cで 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()
}
にスクリプトを変更するには、スクリプトにプレーンテキストのパスワードをハードコードに非常に悪い考えです。 (全員が見るためにインターネットに投稿するのも良いことではありません) –