Windows updates: 4 tidy up get-update

Looking at the get-update function we created earlier I wanted to tidy it up a bit.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
function get-update {
[CmdletBinding()] 
param
 ( 
 
[switch]$hidden
 
) 

PROCESS{

$session = New-Object -ComObject Microsoft.Update.Session
$searcher = $session.CreateUpdateSearcher()

# 0 = false & 1 = true
if ($hidden
){
 
$result = $searcher.Search(“IsInstalled=0 and Type=’Software’ and ISHidden=1″
 )
}

else
 {
 
$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”
} 

}#process

<# .SYNOPSIS Discovers available updates .DESCRIPTION Interrogates Windows updates for available software updates only. Optional parameter to display hidden updates .PARAMETER hidden A switch to display the hidden updates .EXAMPLE get-update Displays non-hidden updates .EXAMPLE get-update -hidden Displays hidden updates #>

}

Primary changes are:

  • to add a switch to the function to control the display of hidden updates
  • count the available updates and display message if there aren’t any
  • add more properties to the output- 7 properties defaults to a list so more readable as well
  • add comment based help
About these ads
This entry was posted in COM, IT Security, PowerShell V2. Bookmark the permalink.

5 Responses to Windows updates: 4 tidy up get-update

  1. Quirel says:

    This is nice.

    But do you know a way to just get driver updates?

    It would be cool to have a function do get all the available windows printer drivers from windows update.

  2. You substitute Driver for Software in the Type.

    I’ve posted a function that does this BUT it shows only those drivers available through Windows updates it won’t show drivers only available from the original manufacturer

  3. whats4lunch says:

    Hi Richard, how would you get the status of the last update via COM on a list of machines i.e. via QAD-computer ?

  4. Pingback: Windows Updates: remote machines | Richard Siddaway's Blog

  5. Pingback: Windows Updates: remote machines - Richard Siddaway's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s