列出非域系统上所有用户的最后 Windows 密码更改

List Last Windows Password Change For All Users On A Non-Domain System

我已经为连接到 AD 域控制器的系统找到了这个问题的答案。但是,此问题适用于无法连接到域控制器的独立系统。本质上,气隙系统。

简短而贴心:有没有办法列出每个用户最后一次为非域、气隙系统(Windows 7 或 10)更改其 Windows 密码的所有时间立即作为批处理文件或 PowerShell 脚本?

我知道网络用户{username} | find /I "Password last set" 会一次为他们做一个。但是,每台机器 运行 多次这样会很乏味,我们有 60 多个这种类型的系统。因此,如果可能的话,我正在寻找一种一次性完成此操作的方法。

请注意,我们没有为此在 PowerShell 中安装 activedirectory 模块的选项。此外,由于大多数系统是 Windows 7,我们无法访问 Bash 命令行工具,而这些工具在 Windows 10.

中可用。

感谢与此相关的任何和所有帮助。

这是使用 ADSI WinNT 提供程序的一种方法:

$computerName = [Net.Dns]::GetHostName()  # i.e., local computer
$computer = [ADSI] "WinNT://$computerName,Computer"
$childObjects = $computer.Children
foreach ( $childObject in $childObjects ) {
  if ( $childObject.Class -eq "User" ) {
    if ( $childObject.PasswordAge[0] -gt 0 ) {
      $pwdLastSet = (Get-Date).AddSeconds(-$childObject.PasswordAge[0])
    }
    else {
      $pwdLastSet = $null
    }
    $childObject | Select-Object `
      @{Name="AdsPath";         Expression={$_.AdsPath}},
      @{Name="PasswordLastSet"; Expression={$pwdLastSet}}
  }
}