header image

Windows Updates: remote machines

Posted by: | June 25, 2011 | No Comment |

 

My main blog is now at http://msmvps.com/blogs/RichardSiddaway/Default.aspx but I also maintain http://richardspowershellblog.wordpress.com/ as a mirror and in case I want the two to diverge at some point.

My recent posts on accessing Windows updates – especially when testing for available updates have raised a number of comments

http://msmvps.com/blogs/richardsiddaway/archive/2011/06/12/windows-updates-4-tidy-up-get-update.aspx

http://richardspowershellblog.wordpress.com/2011/06/12/windows-updates-4-tidy-up-get-update/

One very interesting question is about getting information on the state of updates on remote machines.

We are using COM classes in these functions. It is possible for programmers to access COM objects on remote machines but it isn’t an easy proposition in PowerShell. The best way round this I can think of is to do something like this

get-qadcomputer |
foreach {
invoke-command -filepath c:\scripts\getupdates.ps1 -ComputerName $_.Name

}

The getupdates script would contain this code

$session = New-Object -ComObject Microsoft.Update.Session            
$searcher = $session.CreateUpdateSearcher()            
            
$result = $searcher.Search("IsInstalled=0 and Type='Software' and ISHidden=0" )            
            
if ($result.Updates.Count -gt 0){            
 $result.Updates |             
 select Title, IsHidden, IsDownloaded, IsMandatory,             
 IsUninstallable, RebootRequired, Description            
}            
else {            
 Write-Host " No updates available"            
}

Alternatively leave it as a function and add a call to the function as the last line of the script. I’ll be returning to this idea in a little while as I want to do some more on automating updates across my test environment

under: COM, PowerShellV2