我想检查某台计算机上是否安装了选定的更新。
这是我到目前为止的尝试:
$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
和两个变量中的项目。
这里有两个问题:
Out-String
使得很难比较对象,因为你破坏了返回对象的数组结构并创建了一个字符串数组,每个字母都是自己的字段。不要那样做。-IncludeEqual
Compare-Object
开关并以相同方式更改您的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 "=="}