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

发布于 2024-08-26 07:17:31 字数 116 浏览 5 评论 0原文

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

I've created a set of 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小女人ら 2024-09-02 07:17:31

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

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文