windows - Powershell,如何获取上次 Windows 更新安装日期或至少检查更新?

标签 windows powershell

我正在尝试找到一种方法来检索安装或检查最后一次 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/

相关文章:

c - 用c打开rar文件

windows - 如何在 Windows 上的 Vagrant 中使用 rsync 共享文件夹?

c++ - 手动创建PE

sql-server - 在 ssis foreach 容器中运行 powershell 脚本时没有结果

powershell - 删除带有 [info] 的行后的所有文本

c# - 从 PowerShell 调用时无法在 dll 中转换透明代理,但在 C# 控制台应用程序中成功

windows - 如何在 CMake (Windows) 中检索用户环境变量

windows - Git - 切换分支(窗口)和未提交的更改

powershell - 在 PowerShell 版本 2 中检查进程和进程状态并根据单个进程或多个进程获得两个不同的输出?

powershell - 在远程机器上使用 Powershell 启动和停止 APP 池