yobbo
yobbo

Reputation: 23

Powershell match array and pipe to process

I'm attempting to find all hotfixes declared in the $unhotfix array, then uninstall each if found.

$unhotfix ="KB2966826","KB2966827","KB2966828"

Get-Hotfix | ? (HotFixId -match $unhotfix) | `
${wusa.exe /uninstall /kb:$_.HotfixId /norestart /log} | wait-process

Using the following works for comparing one value:

Get-Hotfix | ? (HotFixId -match "KB2966826") | select HotFixId

However, I am missing something about matching arrays

Get-Hotfix | ? (HotFixId -match $unhotfixid) | select HotFixId

Gives no results.

Upvotes: 1

Views: 229

Answers (2)

mjolinor
mjolinor

Reputation: 68243

Get-Hotfix has an -Id parameter that accepts an array of hotfix names.

Get-Hotfix -Id $unhotfix

Upvotes: 1

Thomas Stringer
Thomas Stringer

Reputation: 5862

Get-HotFix | 
    Where-Object {$unhotfix.Contains($_.HotFixId)}

What this does it tests for the array of hotfix listings, and if it finds the HotFixId in that array, it'll return the matching hotfixes.

Upvotes: 1

Related Questions