当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录

作者:精品下载站 日期:2024-12-14 19:13:21 浏览:15 分类:玩电脑

如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录


Windows 系统会定期更新最新补丁以提高系统性能。 Microsoft 将服务和补丁作为免费更新服务的一部分发布,以增强 Windows 计算体验。这些更新是根据系统设置自动安装的,很少需要最终用户的输入。免费更新是 Windows 维护和支持的一部分,可发布软件以有效修复错误。为了确保安全计算,Windows 更新可确保系统保持最新状态,包括最新的安全补丁、修补程序和错误修复。

用户可以使用 PowerShell、命令行检查更新历史记录,也可以通过 Windows 设置用户界面检查更新历史记录。在本文中,我们讨论如何使用任务自动化和配置管理工具(例如 PowerShell)列出 Windows 更新事件的所有历史记录。人们还可以获得有关作为软件补丁的一部分下载的所有当前修补程序或快速修复工程更新的信息。

使用 PowerShell 检查 Windows 更新历史记录

转到“开始”菜单并搜索 Windows PowerShell。右键单击它,然后单击以管理员身份运行。

在命令行中编写以下命令,列出已安装的修补程序及其 ID、安装信息、说明等。

wmic qfe list

[玩转系统] 如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录

您还可以键入以下命令来列出修补程序及其相关描述。

get-wmiobject -class win32_quickfixengineering

[玩转系统] 如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录

此外,还可以向计算机写入查询以获取更新历史记录,并返回指向 Windows 系统上的匹配记录列表的指针。编写查询是为了在 PowerShell 中列出 WUA 历史记录,方法是定义一些函数,将结果代码的 WUA 历史记录事件转换为名称,并获取最后和最新的 50 个 WUA 历史记录。您可以修改对象以列出任意数量的更新事件的过去历史记录。

[玩转系统] 如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录

# Convert Wua History ResultCode to a Name # 0, and 5 are not used for history # See https://msdn.microsoft.com/en-us/library/windows/desktop/aa387095(v=vs.85).aspx

function Convert-WuaResultCodeToName
{
param( [Parameter(Mandatory=$true)]
[int] $ResultCode
)
$Result = $ResultCode
switch($ResultCode)
{
2
{
$Result = "Succeeded"
}
3
{
$Result = "Succeeded With Errors"
}
4
{
$Result = "Failed"
}
}
return $Result
}
function Get-WuaHistory
{
# Get a WUA Session
$session = (New-Object -ComObject 'Microsoft.Update.Session')
# Query the latest 1000 History starting with the first recordp
$history = $session.QueryHistory("",0,50) | ForEach-Object {
$Result = Convert-WuaResultCodeToName -ResultCode $_.ResultCode
# Make the properties hidden in com properties visible.
$_ | Add-Member -MemberType NoteProperty -Value $Result -Name Result
$Product = $_.Categories | Where-Object {$_.Type -eq 'Product'} | Select-Object -First 1 -ExpandProperty Name
$_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.UpdateId -Name UpdateId
$_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.RevisionNumber -Name RevisionNumber
$_ | Add-Member -MemberType NoteProperty -Value $Product -Name Product -PassThru
Write-Output $_
}
#Remove null records and only return the fields we want
$history |
Where-Object {![String]::IsNullOrWhiteSpace($_.title)} |
Select-Object Result, Date, Title, SupportUrl, Product, UpdateId, RevisionNumber
}

然后,现在键入以下命令以获取更新的历史记录事件以及结果日期、更新标题、支持 URL 和更新 ID。

# Get all the update History, formatted as a table

Get-WuaHistory | Format-Table

[玩转系统] 如何使用 PowerShell 或 CMD 检查 Windows 更新历史记录

就这样。

源自 stackoverflow.com。

使用命令提示符检查 Windows 更新历史记录

在提升的 CMD 中执行以下命令:

wmic qfe list

要查找特定更新,您可以使用 KB 编号,例如对于 KB1234567,请使用:

wmic qfe | find "1234567"

如何在 PowerShell 中列出 Windows 更新?

使用 Win + S 打开 Windows 搜索并键入 PowerShell。找到它后,启动它。完成后,执行以下命令。您也可以在 Windows 终端上使用它。

wmic qfe list

我在 Windows 11 中需要 PowerShell 吗?

PowerShell 是一个强大的跨平台工具,如果您想使用脚本命令更改系统设置并自动执行任务,则需要 Windows 11 中的 PowerShell。Windows 11 的一个优点是您也可以在 Windows 终端中执行 PowerShell 命令。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯