我正在尝试找到一种检索最后一个Windows更新已安装或已检查的日期/时间的方法。目前,我找到了一个函数,可以列出最近的Windows更新,但是对于这样一个简单的功能来说,它包含的数据太多、太臃肿了。其次,我尝试访问注册表,但是没有成功检索到我需要的值。我在Windows 10机器上进行测试,但是该软件可能驻留在Windows Server 2012 R2上。以下是我尝试过的一些代码示例:
此外,只需要尝试Get-ChildItem命令。
$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中检查过,这个键不存在。前往“Windows更新”路径只显示应用程序更新而不是Windows更新。
编辑 使用以下命令似乎更接近我的目标: Get-HotFix | Where {$_.InstallDate -gt 30}
但是,如何只检索最近30天内安装的内容?这并没有显示出许多结果,即使使用 Select $_.InstallDate
.
gwmi win32_quickfixengineering |sort installedon -desc |?{ ((get-date)-$_.installedon) -lt 30 }
- Loïc MICHEL