when does UpdateID not equal UpdateID for Windows Update searches?

I'm trying to automate some Microsoft updates on Windows 7.  I'm trying to find some already installed updates, then uninstall them.  The weird thing is that I can do it for one KB, but not for another KB. 

I use the same steps for each KB: find it in the installed history, get its historical UpdateID, then use the searcher to locate the specific item again to use with the Uninstall method later.  I am unable to use the Searcher for one of the KBs, even though it is already on my system.

$updater = New-Object -ComObject Microsoft.Update.Session            
$searcher = $updater.CreateUpdateSearcher()            
$history = $searcher.QueryHistory(1,$searcher.GetTotalHistoryCount()) # retrieve the full history of installed updates
$kbs = ('KB3068708','KB3022345')
foreach ($kb in $kbs) {
    $removable = $history | where {$_.title -match $kb}
    if ($removable -ne $null) {
        $id = $removable.UpdateIdentity.UpdateID
        write-host "$kb found in history with UpdateID=$id"
        $search = 'UpdateID=''' + $removable.UpdateIdentity.UpdateID + ''''
        $removeit = $searcher.Search($search)
        if ($removeit.Updates.Count -gt 0) {
            write-host "Success!  Able to search the update based on its historical updateIdentity.UpdateID value"
        } else {
            write-host "Failure!  UNable to search the update based on its historical updateIdentity.UpdateID value"
        }
    }
}

I get these results:

KB3068708 found in history with UpdateID=0cd9efd9-d371-4e7d-8381-15ae5b55ea79
Success!  Able to search the update based on its historical updateIdentity.UpdateID value
KB3022345 found in history with UpdateID=94ec92df-8687-4f9e-acca-2c4ac8bf3b19
Failure!  UNable to search the update based on its historical updateIdentity.UpdateID value
What am I doing wrong here?
September 2nd, 2015 1:06pm

Many KBs cannot be uninstalled.  Check the uninstallable flag before trying to remove.  "IsRemovable"  ... or "IsUnistalabel"  or something like that.

Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 1:42pm

I added "write-host $removable.UninstallationNotes" to the above loop.  Both items are uninstallable, and I got these results:

KB3068708 found in history with UpdateID=0cd9efd9-d371-4e7d-8381-15ae5b55ea79
This software update can be removed by selecting View installed updates in the Programs and Features Control Panel.
Success!  Able to search the update based on its historical updateIdentity.UpdateID value
KB3022345 found in history with UpdateID=94ec92df-8687-4f9e-acca-2c4ac8bf3b19
This software update can be removed by selecting View installed updates in the Programs and Features Control Panel.
Failure!  UNable to search the update based on its historical updateIdentity.UpdateID value

I omitted my section on uninstalling the item from the original code sample because I couldn't get past this issue with using the .Search() method beforehand. I'd rather just continue using the .QueryHistory() objects since I've already got them, but the installer's .Uninstall() method disliked that object type, so apparently I have to figure out a way to complete a successful .Search() instead.  :(

If I could search based on KB instead of ObjectID, that would make my life simpler too.  Why it isn't included, I can't fathom, since KB is the reference number that scripters will know.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa386526.aspx (Search method)


September 2nd, 2015 2:06pm

I added "write-host $removable.UninstallationNotes" to the above loop.  Both items are uninstallable, and I got these results:

KB3068708 found in history with UpdateID=0cd9efd9-d371-4e7d-8381-15ae5b55ea79
This software update can be removed by selecting View installed updates in the Programs and Features Control Panel.
Success!  Able to search the update based on its historical updateIdentity.UpdateID value
KB3022345 found in history with UpdateID=94ec92df-8687-4f9e-acca-2c4ac8bf3b19
This software update can be removed by selecting View installed updates in the Programs and Features Control Panel.
Failure!  UNable to search the update based on its historical updateIdentity.UpdateID value

I omitted my section on uninstalling the item from the original code sample because I couldn't get past this issue with using the .Search() method beforehand. I'd rather just continue using the .QueryHistory() objects since I've already got them, but the installer's .Uninstall() method disliked that object type, so apparently I have to figure out a way to complete a successful .Search() instead.  :(

If I could search based on KB instead of ObjectID, that would make my life simpler too.  Why it isn't included, I can't fathom, since KB is the reference number that scripters will know.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa386526.aspx (Search method)


  • Edited by Terry.Walker Wednesday, September 02, 2015 6:13 PM
Free Windows Admin Tool Kit Click here and download it now
September 2nd, 2015 6:03pm

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

Other recent topics Other recent topics