我创build了一组具有特定pipe理员密码的虚拟机(Windows Server); 这些虚拟机已分配给用户,可能正在使用中。 我想知道用户是否更改了pipe理员密码,并进行检查,以便用户不会注意到。 在PowerShell中有什么好的解决scheme?
您可以创建一个PSCredential,然后尝试从主机获取WmiObject。 就像是:
$computerNames = "host1", "host2" $pw = ConvertTo-SecureString "adminpw" -AsPlainText -Force foreach($computerName in $computerNames) { $cred = New-Object System.Management.Automation.PSCredential("$computerName\Administrator", $pw) try { Get-WmiObject win32_bios -ComputerName $computerName -Credential $cred Write-Host "$computerName = Password not changed." } catch [System.UnauthorizedAccessException] { Write-Host "$computerName = Password changed." } }