Exclude a KB number from a Windows update Powershell Script.

I am having a heck of a time removing a patch from the $updates patch collection. We have one that we do not want to install. Using attempts like $updates.remove are not working. Has anyone accomplished this before?

thanks

$updateSession = new-object -com "Microsoft.Update.Session"
Write-Host("Searching for applicable updates...") -Fore Green
$updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates
$downloader = $updateSession.CreateUpdateDownloader()         
$downloader.Updates = $Updates

foreach ($y in $updates){$y.kbarticleIDs}

(section to remove a KB from $updates, based on KB)

 

  • Edited by Pauld_26 Friday, January 06, 2012 11:03 PM
January 6th, 2012 10:51pm

May be:

$updates | Where {$_.KBArticleIDs -ne "2483139"}

Free Windows Admin Tool Kit Click here and download it now
January 6th, 2012 11:04pm

This can't be done as far as I can see.  $updates is not a collection/array, it is a com object.  The only thing you can do is specify the updates you do or don't want to install in the
January 7th, 2012 7:01am

See the following reference:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa386526(v=vs.85).aspx

Free Windows Admin Tool Kit Click here and download it now
January 7th, 2012 7:35am

Some examples of using Microsoft.Update.Session you can see here:

http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

January 7th, 2012 9:49am

Here is a little script that will create a hash table of all applicable updates, and their associated UUID's.  This can be used to look up the UUID, to use as a criteria when searching again:

 

$upids =  @{}
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$results = $searcher.search("Type='software' AND IsInstalled = 0")
$Results.Updates | 
     ForEach-Object { $upids.Add($_.Title, $_.Identity.UpdateID) }
$upids

Free Windows Admin Tool Kit Click here and download it now
January 7th, 2012 9:59am

Also, see the following Scripting Guy blog:

http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/11/how-can-i-search-for-download-and-install-an-update.aspx

January 7th, 2012 10:30am

Wow, thanks for all the help! I will tear into all of these, and post a simple code that works. which.

1. Runs a Windows update.

2. If X,y KB is found, skip them, remove them from the collection,

thanks!

 

Free Windows Admin Tool Kit Click here and download it now
January 9th, 2012 2:20pm

Good luck.  Look forward to hearing how you get on.  Come back here with any queries.
January 9th, 2012 2:43pm

The correct answer is to use -notin while declaring an array of kb numbers.

$kbs = "2483139","3006121"

$searchresult.updates |?{$_.KBArticleIDs -notin $kbs} |select title

Free Windows Admin Tool Kit Click here and download it now
December 11th, 2014 5:54pm

The correct answer is to use -notin while declaring an array of kb numbers.

$kbs = "2483139","3006121"

$searchresult.updates |?{$_.KBArticleIDs -notin $kbs} |select

September 8th, 2015 4:30am

The correct answer is to use -notin while declaring an array of kb numbers.

$kbs = "2483139","3006121"

$searchresult.updates |?{$_.KBArticleIDs -notin $kbs} |select

Free Windows Admin Tool Kit Click here and download it now
September 8th, 2015 8:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics