header image

Windows Updates: 1 Discovering Updates

Posted by: | June 10, 2011 | 1 Comment |

I want to spend a few posts looking at Windows updates. There is a COM object model that enables us to work with the updates system.

Any update processing starts with discovering the updates that are available

001
002
003
004
005
006
007
008
function get-update {
$session = New-Object -ComObject Microsoft.Update.Session
$searcher = $session.CreateUpdateSearcher()

$result = $searcher.Search("IsInstalled=0 and Type=’Software’" )

$result.Updates | select Title, IsHidden
}

 

Create an object representing an update session

Create an update searcher and search for software updates that aren’t installed.

We can then output the update title and if its hidden or not.  Other properties are available.

under: COM, PowerShellV2

1 Comment

  1. By: GiZmO on August 1, 2013 at 3:17 am      

    If you replace the line:
    $session = New-Object -ComObject Microsoft.Update.Session

    And instead place these two lines:
    param($ComputerName=$env:COMPUTERNAME)
    $Session = [Activator]::CreateInstance([Type]::GetTypeFromProgID(“Microsoft.Update.Session”,$ComputerName))

    You’ll be able to get status for remote machines as well.