npb consultants

IT Consultancy Services

  • Home
  • Downloads
  • Blog
  • Contact
  • Portal
« Open Audit
List Number of Mailboxes per Exchange Server »

Querying WSUS with Powershell

Out of the box, WSUS is capable of reporting update status in a number of permutations, but I always seem to need some combination that I can’t easily derive using the GUI.

I recently needed to determine the status of a particular update (KB958644) for a number of computers that spanned different WSUS groups. I knew that there was a .NET API for WSUS management and so Powershell seemed to the most appropriate tool to use. I found this script example which got me started.

After a bit of head scratching I came up with the script below. It reads a list of computer names from a plain text file (Computers.txt) and calls the GetUpdateStatus function for each computer listed, passing the computer name and update string to the function.

The GetUpdateStatus function pulls the computer object from WSUS and then attempts to locate the update specified by the string. The status of the update is then returned.

[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
 
if (!$wsus) {$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();}
 
function GetUpdateStatus([string]$a, [string]$b)
{
  $ComputerScope = new-object Microsoft.UpdateServices.Administration.ComputerTargetScope;
  $ComputerScope.NameIncludes = $a;
 
  $UpdateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
  $UpdateScope.ExcludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::NotApplicable;
  $UpdateScope.TextIncludes  = $b;
 
  $Computers = $wsus.GetComputerTargets($ComputerScope);
 
  $Computers | foreach-object{
    $_.FullDomainName + " (Status @ " + $_.LastReportedStatusTime + ")" | write-host;
 
    $Updates = $_.GetUpdateInstallationInfoPerUpdate($UpdateScope);
    $Updates | foreach-object{
      $Update = $wsus.GetUpdate($_.UpdateId);
      "   "+$Update.Title+"   {"+$_.UpdateInstallationState +"}" | write-host;
    }
  }
}
 
cls
Get-Content Computers.txt | Foreach-Object {GetUpdateStatus $_ "KB958644"}

This entry was posted on Wednesday, February 11th, 2009 at 10:42 am and is filed under Powershell, Scripting. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Click here to cancel reply.

  • Search

  • Pages

    • Nick Brown
  • Archives

    • November 2009
    • April 2009
    • February 2009
    • January 2009
  • Categories

    • Open Audit (1)
    • Scripting (2)
      • Powershell (2)
    • Windows (2)
      • Deployment (1)
      • Vista (1)
 

©2007 All Rights Reserved.  •  Design by Free CSS Templates  •  Icons by FAMFAMFAM.