PowerShell 技能连载 - 寻找丢失的更新

PowerShell 可以使用 Windows Update 客户端相同逻辑查询缺少的更新:

1
2
3
4
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates | Select-Object Title

下面是返回更新标题和知识库编号(如果可用)的更复杂的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateupdateSearcher()
$Updates = @($UpdateSearcher.Search("IsHidden=0 and IsInstalled=0").Updates)
$Updates |
ForEach-Object {
$pattern = 'KB\d{6,9}'
if ($_.Title -match $pattern)
{
$kb = $matches[0]
}
else
{
$kb = 'N/A'
}
[PSCustomObject]@{
Title = $_.Title
KB = $kb
}
} | Out-GridView

PowerShell 技能连载 - 寻找丢失的更新

http://blog.vichamp.com/2019/06/13/finding-missing-updates/

作者

吴波

发布于

2019-06-13

更新于

2022-07-06

许可协议

评论