2015-08-16 42 views
1

我試圖找到$ unhotfix數組中聲明的所有修補程序,然後卸載每個如果找到。Powershell匹配數組和管道來處理

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

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

使用下面的作品比較一個值:

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

不過,我失去了一些東西大約相同排列

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

沒有給出結果。

回答

1

Get-Hotfix有一個-Id parameter接受一組修復程序名稱。

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

這裏做它測試的修補程序列表的數組,如果數組中找到HotFixId,它會返回匹配的修補程序。

+1

'Contains()'方法區分大小寫。我建議使用'-contains'運算符代替。 –