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
|