Horkryzard
Horkryzard

Reputation: 13

Compare installed Windows updates against defined array

I would like to check if selected updates are installed on a certain computer.

This is my attempt so far:

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


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

The main problem is, that Compare-Object could't find items that are in $HotfixRequared and in both variables at the same time.

Upvotes: 1

Views: 204

Answers (1)

Paxz
Paxz

Reputation: 3046

Two problems here:

  1. The Out-String makes it hard to compare the objects since you destroy the array structure of the returned object and create a string-array with every letter being its own field. Don't do that.
  2. You have to use the -IncludeEqual Switch of Compare-Object and change your Where-Object query in the same manner.

This should give you all Hotfixes that are in $HotfixRequarded and in both:

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


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

Upvotes: 1

Related Questions