Powershell,如何获取上次 Windows 更新安装的日期或至少检查更新的日期? [英] Powershell, How to get date of last Windows update install or at least checked for an update?

查看:26
本文介绍了Powershell,如何获取上次 Windows 更新安装的日期或至少检查更新的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来检索上次安装或检查 Windows 更新的日期/时间.

I am trying to find a way of retrieving the date/time of which the last windows update was either installed, or checked for.

到目前为止,我已经找到了一个允许列出最近的 Windows 更新的功能,但是对于这样一个简单的功能来说,它的数据太多并且过于臃肿.其次,我尝试访问注册表,尽管我没有找到我所追求的值.

So far I have found a function that allows to list recent Windows Updates, but it is far too much data and too bloated for such a simple function. Secondly I have tried to access the registry although I am having no luck in retriving the value I am after.

我正在 Windows 10 机器上对此进行测试,尽管该软件可能会驻留在 Windows Server 2012 R2 上.

I am testing this on a Windows 10 Machine although the software will probably reside on Windows Server 2012 R2.

这是我尝试过的一些代码的示例:

Here is an example of some of the code I have tried:

$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

Also, just trying the Get-ChildItem

$hello = Get-ChildItem -Path "hkcu:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\"

foreach ($a in $hello) {

$a

}

我已在 regedit 中签入,但此密钥不存在.转到Windows 更新"路径仅显示应用更新,而不显示 Windows 更新.

I've checked in regedit and this key does not exist. Going to the "Windows Update" path shows only App Updates and not Windows updates.

编辑通过这条线,我似乎更接近我的目标:获取热修复 |其中 {$_.InstallDate -gt 30}

EDIT I seem to be closer to my goal with this line: Get-HotFix | Where {$_.InstallDate -gt 30}

但是如何只检索过去 30 天内安装的那些?即使使用 Select $_.InstallDate

However how to I only retrive those of which have been installed in the last 30 days? And this doesnt show many results, even using Select $_.InstallDate

推荐答案

一个选项:

 gwmi win32_quickfixengineering |sort installedon -desc 

另一种选择,使用 com 对象 Microsoft.Update.Session 可以在这里找到:https://p0w3rsh3ll.wordpress.com/2012/10/25/getting-windows-updates-installation-history/简而言之:

Another alternative, using the com object Microsoft.Update.Session can be find here : https://p0w3rsh3ll.wordpress.com/2012/10/25/getting-windows-updates-installation-history/ in short :

$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 {$_}

这篇关于Powershell,如何获取上次 Windows 更新安装的日期或至少检查更新的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆