Keeping WSUS Happy using PowerShell

Some time ago i found a great . I used this at my demo lab and customer sites. WSUS need a little help Winking smile

  • Someone need to deny all patches that are superseeded, this does not happen automatically.
  • Someone needs to cleanup old content, computers, patches and such, this does not happen automatically.
  • Someone needs to care for the database, this does not happen automatically.


The script will do the following

Connect to a database

you might need to this in the script.

#For Internal Database, use $WSUSDB = ‘\\.\pipe\##WID\tsql\query’
#For Express, use $WSUSDB = ‘\\.\pipe\MSSQL$SQLEXPRESS\\query’

Get the Superseeded

Here is the Posh that fixes that:

$SuperSeededUpdates = Get-WsusUpdate -Approval AnyExceptDeclined -Classification All -Status Any | Where-Object -Property UpdatesSupersedingThisUpdate -NE -Value ‘None’ -Verbose
$SuperSeededUpdates | Deny-WsusUpdate –Verbose

Cleanup WSUS

We run each step sepratly, however, you can change that and run everything in one line…

Cleanup the DB

Last part runs sqlcmd using a .SQL file from MSFT Gallery, and yes, you can download and install the for SQL and use that instead. Most of your customers dont have thoose installed, so sqlcmd.exe it is