So today our WSUS server was flagging up that it was out of drive space. No problem I said, I’ll just clear out some updates and let it run as it has once more, for the past 10 years.
Oh dear… This box has 1.5TBs of updates, for every single Microsoft product that requires them, since 2009…. XP, Vista, 100 different flavours of Embedded… Microsoft… Works? Yeah, this gotta go.
Firing up the Server Cleanup Wizard in the WSUS msc ‘Options’ section, with all options checked, I set it on it’s way to slash through the overgrowth of updates. But alas, the cleanup tool sits and does nothing before failing 15 minutes later.
But have no fear! Some random guy I found on Spiceworks is here! I stumbled upon this post with this fancy script that promises to cure all my WSUS woes and purge the overgrowth of my WSUS server in ways akin to the recent fires in the Amazon. With wanton regard and total destruction.
Lifting the script that ‘spicehead-fjb1g’ created from here, I modified it a little so it gives a bit more feedback:
cls
$looponcemore = $true
$attempts = 1
while ($looponcemore -eq $true) {
$looponcemore = $false
# Show date/time to show elapsed time between attempts
get-date
write-host -ForegroundColor Green "Running Cleanup(Press Ctrl-C/Ctrl-Q to stop)..."
Try
{
##Use custom switches here, one at a time recommended:
# -CleanupObsoleteComputers -CleanupObsoleteUpdates
# -CleanupUnneededContentFiles -CompressUpdates
# -DeclineExpiredUpdates -DeclineSupersededUpdates
write-host -ForegroundColor Green "Attempting cleanup... Attempt number: $attempts"
Invoke-WsusServerCleanup -CleanupObsoleteUpdates
}
Catch
{
write-host -ForegroundColor Green "Fell over.. Running again"
$looponcemore = $true
$attempts++
Start-Sleep -Seconds 15
}
}
As per the comments, you should only run one -command at a time. Let this run overnight and hopefully it will get through a little bit at a time per crash.
Just throw that into an administrator Powershell ISE window and let it run.
Good luck!