当前位置:萝卜系统 > 硬件软件教程 > 详细页面

如何使用PowerShell查看Windows Update更新历史记录

如何使用PowerShell查看Windows Update更新历史记录

更新时间:2023-07-12 文章作者:未知 信息来源:网络 阅读次数:

Windows操作系统作为优秀的操作系统,由开发操作系统的微软公司控制接口和设计,公开标准,因此,有大量商业公司在该操作系统上开发商业软件。

用户除了可以通过「Windows 设置」——「更新和安全」界面中查看更新历史记录外,还可以通过 PowerShell 来查看 Windows Update 更新历史记录。下面我们就介绍如何使用任务自动化和配置管理工具(如 PowerShell)列出 Windows Update 事件的所有历史记录。

此前我们也介绍过如何使用 PowerShell 查看 Windows 10 Build 升级历史记录

使用PowerShell查看Windows Update更新历史记录

1使用?Windows + X?快捷键打开快捷菜单——选择?Windows PowerShell(管理员)

2执行如下命令,即可查看到当前计算机中已安装补丁的详细信息,包括:标题、描述、KB 号、安装日期和状态等等。

wmic qfe list

如何使用PowerShell查看Windows Update更新历史记录

3也可以键入以下命令以列出修补程序 KB 及其关联的描述。

get-wmiobject -class win32_quickfixengineering

如何使用PowerShell查看Windows Update更新历史记录

当然,也可以向 Windows PC 更新历史记录写入查询函数,以返回指向 Windows 系统上匹配列表记录的指针。

  1. function Convert-WuaResultCodeToName
  2. {
  3. param(
  4. [Parameter(Mandatory=$true)]
  5. [int] $ResultCode
  6. )
  7. ?
  8. $Result = $ResultCode
  9. switch($ResultCode)
  10. {
  11. 2 {
  12. $Result = "成功"
  13. }
  14. 3 {
  15. $Result = "成功但包含错误"
  16. }
  17. 4 {
  18. $Result = "失败"
  19. }
  20. }
  21. ?
  22. return $Result
  23. }
  24. ?
  25. function Get-WuaHistory
  26. {
  27. ?
  28. $session = (New-Object -ComObject 'Microsoft.Update.Session')
  29. ?
  30. $history = $session.QueryHistory("",0,1000) | ForEach-Object {
  31. $Result = Convert-WuaResultCodeToName -ResultCode $_.ResultCode
  32. ?
  33. $_ | Add-Member -MemberType NoteProperty -Value $Result -Name Result
  34. $Product = $_.Categories | Where-Object {$_.Type -eq 'Product'} | Select-Object -First 1 -ExpandProperty Name
  35. $_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.UpdateId -Name UpdateId
  36. $_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.RevisionNumber -Name RevisionNumber
  37. $_ | Add-Member -MemberType NoteProperty -Value $Product -Name Product -PassThru
  38. ?
  39. Write-Output $_
  40. }
  41. ?
  42. $history |
  43. Where-Object {![String]::IsNullOrWhiteSpace($_.title)} |
  44. Select-Object Result, Date, Title, SupportUrl, Product, UpdateId, RevisionNumber
  45. }

在定义好函数之后,就可以用来获取更新:

Get-WuaHistory | Format-Table

如何使用PowerShell查看Windows Update更新历史记录


Windows操作系统对硬件支持良好。

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行

网站地图xml | 网站地图html