开发者

How to implement a password change check in Powershell?

I've created a set of开发者_Go百科 virtual machines (Windows Server) with a specific admin password; these VMs have been assigned to users, and may be in use. I want to know if the user changed the admin password, and do the check so the user doesn't notice. What are good solutions in powershell?


You could create a PSCredential, then attempt to get a WmiObject from the host. Something like:

$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."
  }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜