PowerShell 技能连载 - 查找已安装和缺失的更新(第一部分)

Windows 可以自动确定系统中缺失的更新,在有 Internet 连接的情况下。PowerShell 可以使用相同的系统接口来查询该信息。以下代码返回系统中所有已安装的更新:

1
2
3
4
5
6
7
8
9
#requires -Version 2.0

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$updates = $Searcher.Search("IsInstalled=1").Updates

$updates |
Select-Object Title, LastDeployment*, Description, SupportUrl, MsrcSeverity |
Out-GridView

要查看缺失的更新,请将 IsInstalled=1 改为 IsInstalled=0

1
2
3
4
5
6
7
8
9
#requires -Version 2.0

$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$updates = $Searcher.Search("IsInstalled=0").Updates

$updates |
Select-Object Title, LastDeployment*, Description, SupportUrl, MsrcSeverity |
Out-GridView

本文国际来源:Finding Installed Updates (and searching for missing) (Part 1)

评论