将已安装的Windows更新与已定义的阵列进

问题描述 投票:1回答:1

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

这是我到目前为止的尝试:

$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和两个变量中的项目。

powershell windows-update
1个回答
1
投票

这里有两个问题:

  1. Out-String使得很难比较对象,因为你破坏了返回对象的数组结构并创建了一个字符串数组,每个字母都是自己的字段。不要那样做。
  2. 您必须使用-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 "=="}
© www.soinside.com 2019 - 2024. All rights reserved.