Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何在Powershell中实现密码更改检查?_Windows_Powershell_Powershell 2.0 - Fatal编程技术网

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

Windows 如何在Powershell中实现密码更改检查?,windows,powershell,powershell-2.0,Windows,Powershell,Powershell 2.0,我已经创建了一组具有特定管理员密码的虚拟机(Windows Server);这些虚拟机已分配给用户,并且可能正在使用中。我想知道用户是否更改了管理员密码,并进行检查,以便用户不会注意到。powershell中有哪些好的解决方案?您可以创建PSCredential,然后尝试从主机获取WMIOObject。比如: $computerNames = "host1", "host2" $pw = ConvertTo-SecureString "adminpw" -AsPlainText -Force

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

您可以创建PSCredential,然后尝试从主机获取WMIOObject。比如:

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

}