如何在Powershell中实现密码更改检查?

时间:2010-03-20 19:17:30

标签: windows powershell powershell-v2.0

我创建了一组带有特定管理员密码的虚拟机(Windows Server);这些VM已分配给用户,并且可能正在使用中。我想知道用户是否更改了管理员密码,并进行检查以便用户不会注意到。 PowerShell中有哪些好的解决方案?

1 个答案:

答案 0 :(得分:2)

您可以创建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."
  }

}