Manage WSUS 3.0 SP2 with PowerShell

With Windows Server 2012 (WSUS 4.0), Microsoft released a PowerShell module with cmdlets for managing and automating tasks. However, quite a few people are still using WSUS 3.0 which shipped with Server 2008 R2 and unfortunately a module was not provided with this edition.

A common reason I use PowerShell when administrating WSUS environments is when the console doesn’t respond due to unkempt databases. Leaving your WSUS server without declining superseded updates, de-fragmenting the database and re-indexing the database can leave you in a bit of bother when you cant do anything with the console. As there isn’t a module provided, I looked into how I could manage WSUS 3.0 and came up with the following:

param(
[String]$updateServer
)
$useSecureConnection = $False
$portNumber = 8530
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$count = 0
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$useSecureConnection,$portNumber)
write-host "Connected"
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$i = $updateServer.GetUpdates($updatescope)
foreach ($u in $i ){
if ($u.IsSuperseded -eq "True"){
write-host "Decline Update : $u.Title"
$u.Decline()
$count = $count + 1
}
}
write-host "Total Declined Updates: $count"

The script takes a single parameter “updateServer” which is the name of your update server. Then it loads the UpdateServices API, connects to the server and then grabs all updates. It then goes through each and declines them if they are superseded, which would then allow you to run the clean up wizard successfully.

This could be extended to perform other tasks, but to be honest this is the only situation I ever need to use PowerShell with WSUS. I’ll be releasing a post soon on how to keep your WSUS environment tidy and how to automate it all.

Manage WSUS 3.0 SP2 with PowerShell

One thought on “Manage WSUS 3.0 SP2 with PowerShell

Leave a comment