Last active
January 22, 2016 22:52
-
-
Save bklockwood/5b6b8d520d18475e660d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-UpdateList { | |
<# | |
.SYNOPSIS | |
Gets an ISearchResult containing updates from Windows Update. | |
.PARAMETER Computername | |
The target computer. | |
Cannot use an array of computernames here. | |
Defaults to the local PC. | |
.PARAMETER Criteria | |
The search criteria, see http://goo.gl/7nZSPs | |
Left at default, it will return all software updates that have not yet | |
been installed. Driver updates are ignored. | |
.NOTES | |
Returns an IUpdateCollection (http://goo.gl/8C2dbb) named IUpdateCollection | |
IUpdateCollection is type System.__ComObject#{c1c2f21a-d2f4-4902-b5c6-8a081c19a890} | |
WU error codes: http://goo.gl/cSWDY8 | |
.EXAMPLE | |
Get-UpdateList | |
(TODO) | |
.EXAMPLE | |
(Get-UpdateList).Count | |
5 | |
Shows that there are 5 updates available. | |
#> | |
[CmdletBinding()] | |
Param ( | |
[Parameter(ValueFromPipeline=$true, Position=0)] [string]$Computername = ".", | |
[Parameter(ValueFromPipeline=$false, Position=1)] [string]$Criteria = "IsInstalled=0 and Type='Software'" | |
) | |
$Searcher = New-Object -ComObject Microsoft.Update.Searcher | |
$ISearchResult = $Searcher.Search($Criteria) | |
$ISearchResult | |
} | |
function Hide-Update { | |
<# | |
.Synopsis | |
Hides or un-hides updates as specified by KB article number (KBID). | |
.PARAMETER ISearchResult | |
ISearchResult is delivered from Get-UpdateList and is a COM object. | |
(http://goo.gl/pvnUSM) | |
.PARAMETER KBID | |
One or more KBIDs to hide or un-hide. | |
.PARAMETER UNHIDE | |
Switch parameter. If used, the specified KBID(s) will be UN-hidden. | |
.EXAMPLE | |
#> | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0)]$ISearchResult, | |
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$false,Position=1)][string[]]$KBID, | |
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$false,Position=2)][switch]$UnHide | |
) | |
Begin { | |
if ($ISearchResult -eq $null) {$ISearchResult = Get-UpdateList } | |
if ($ISearchResult.pstypenames -notcontains 'System.__ComObject#{d40cff62-e08c-4498-941a-01e25f0fd33c}') { | |
Write-Error "$ISearchResult is not an ISearchResult object (http://goo.gl/pvnUSM)" | |
break | |
} | |
} | |
Process { | |
foreach ($u in $ISearchResult.Updates){ | |
if ($UnHide) { | |
if ($KBID -contains $($u.KbArticleIDs)) {$u.isHidden = $false} | |
} else { | |
if ($KBID -contains $($u.KbArticleIDs)) {$u.isHidden = $true} | |
} | |
} | |
$ISearchResult | |
} | |
} | |
#---- | |
Write-Output "Working ..." | |
Hide-update -KBID 2483139 #Language packs win7 | |
Write-Output "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment