Some time ago i found a great WSUS cleanup script. I used this at my demo lab and customer sites. WSUS need a little help
- 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 change this in the script.
#For Windows Internal Database, use $WSUSDB = ‘\\.\pipe\MICROSOFT##WID\tsql\query’
#For SQL Express, use $WSUSDB = ‘\\.\pipe\MSSQL$SQLEXPRESS\sql\query’
Get the Superseeded Updates
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
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 PowerShell tools for SQL and use that instead. Most of your customers dont have thoose tools installed, so sqlcmd.exe it is