将安装的 Windows 更新与定义的数组进行比较

Compare installed Windows updates against defined array

我想检查某台计算机上是否安装了选定的更新。

这是我目前的尝试:

$HotfixInstaled = Get-Hotfix | Select-Object -Property HotFixID | out-string
$HotfixRequared = @("KB4477029", "KB4486458", "KB4480959")


Compare-Object $HotfixRequared $HotfixInstaled -Property HotFixID | where {$_.sideindicator -eq "<="}

主要问题是,Compare-Object 找不到同时位于 $HotfixRequared 和两个变量中的项目。

这里有两个问题:

  1. Out-String 使得比较对象变得困难,因为您破坏了返回对象的数组结构并创建了一个字符串数组,每个字母都是它自己的字段。不要那样做。
  2. 您必须使用 Compare-Object-IncludeEqual 开关,并以相同的方式更改您的 Where-Object 查询。

这应该会为您提供 $HotfixRequarded 和以下两者中的所有修补程序:

$HotfixInstaled = Get-Hotfix | Select-Object -Property HotFixID
$HotfixRequared = @("KB4477029", "KB4486458", "KB4480959")


Compare-Object $HotfixRequared ($HotfixInstaled.HotFixID) -IncludeEqual| Where-Object {$_.sideindicator -eq "<=" -or $_.sideindicator -eq "=="}