我正在尝试找到一种方法来检索安装或检查最后一次 Windows 更新的日期/时间。
到目前为止,我已经找到了一个允许列出最近的 Windows 更新的功能,但是对于这样一个简单的功能来说,它的数据太多而且过于臃肿。其次,我尝试访问注册表,尽管我没有运气来检索我所追求的值(value)。
我正在 Windows 10 计算机上对此进行测试,尽管该软件可能驻留在 Windows Server 2012 R2 上。
这是我尝试过的一些代码的示例:
$key = “SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\Results\Install”
$keytype = [Microsoft.Win32.RegistryHive]::LocalMachine
$RemoteBase = [Microsoft.Win32.RegistryKey]::OpenBaseKey($keytype,"My Machine")
$regKey = $RemoteBase.OpenSubKey($key)
$KeyValue = $regkey.GetValue(”LastSuccessTime”)
$System = (Get-Date -Format "yyyy-MM-dd hh:mm:ss")
此外,只需尝试 Get-ChildItem
$hello = Get-ChildItem -Path “hkcu:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\”
foreach ($a in $hello) {
$a
}
我已经在 regedit 中检查过,但此 key 不存在。转到“Windows 更新”路径仅显示应用程序更新,而不显示 Windows 更新。
编辑 这条线似乎更接近我的目标: 获取热修复 |其中 {$_.InstallDate -gt 30}
但是如何只检索最近 30 天内安装的那些?这并没有显示很多结果,即使使用 Select $_.InstallDate
最佳答案
一个选项:
gwmi win32_quickfixengineering |sort installedon -desc
另一种选择,使用 com 对象 Microsoft.Update.Session 可以在这里找到:https://p0w3rsh3ll.wordpress.com/2012/10/25/getting-windows-updates-installation-history/ 简而言之:
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$HistoryCount = $Searcher.GetTotalHistoryCount()
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa386532%28v=vs.85%29.aspx
$Searcher.QueryHistory(0,$HistoryCount) | ForEach-Object {$_}
关于windows - Powershell,如何获取上次 Windows 更新安装日期或至少检查更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33732541/