如何在计算机上查询 Windows Update 的“上次检查”信息?

Tyl*_*r N 2 windows windows-registry windows-update powershell

设置中的 Windows 更新页面包含一个Last Checked时间戳,我试图确定是否有可能以某种方式查询机器以获取此信息(通过命令提示符、PowerShell、注册表查询等)

我搜索了Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate我的注册表的一部分,发现没有与我的Last Checked.

有没有办法查询这个?目标是能够查询远程计算机的信息,以避免必须远程访问它。

在此处输入图片说明

运行 PowerShell 命令$(New-Object -ComObject Microsoft.Update.AutoUpdate).Results.LastSearchSuccessDate返回具有匹配日期但时间不匹配的时间戳

在此处输入图片说明

wp7*_*8de 5

按照建议,LastSearchSuccessDate使用 (.NET) 函数将返回的 UTC 时间转换为您的本地时间:

Function Get-LocalTime($UTCTime) {
    $strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
    $TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
    Return [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
}

Get-LocalTime $(New-Object -ComObject Microsoft.Update.AutoUpdate).Results.LastSearchSuccessDate
Run Code Online (Sandbox Code Playgroud)

给我的结果与“检查更新”用户界面中显示的结果相同。

远程执行

Invoke-Command -ComputerName $server -ScriptBlock { 
    Function Get-LocalTime($UTCTime) {
    $strCurrentTimeZone = (Get-WmiObject win32_timezone).StandardName
    $TZ = [System.TimeZoneInfo]::FindSystemTimeZoneById($strCurrentTimeZone)
    Return [System.TimeZoneInfo]::ConvertTimeFromUtc($UTCTime, $TZ)
    }
    
    Get-LocalTime $(New-Object -ComObject Microsoft.Update.AutoUpdate).Results.LastSearchSuccessDate
}; 
Run Code Online (Sandbox Code Playgroud)

  • 对于那些不希望调用命令中的变量或函数的人来说,这是一句... `[System.TimeZoneInfo]::ConvertTimeFromUtc($(New-Object -ComObject Microsoft.Update.AutoUpdate).Results.LastSearchSuccessDate, [System.TimeZoneInfo]::FindSystemTimeZoneById((Get-WmiObject win32_timezone).StandardName))` (2认同)