############################################################################### # # Script to cleanup unused content from WSUS # # created: 23.07.2017 Michael Albert info@michlstechblog.info # # changes: # ############################################################################### [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") # Only needed if the script doesn't run on the WSUS Server [String]$sWSUSServer = "yourWSUSServer" [Boolean]$bSecureConnection = $False [Int32]$iWSUSPort = 8531 try { if([String]::IsNUllOrEmpty($sWSUSServer)) { $oWSUSServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() } else { $oWSUSServer = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer($sWSUSServer,$bSecureConnection,$iWSUSPort) } } catch [Exception] { write-warning ("Cannot connect to WSUS Server: $sWSUSServer. Error: " + $_) exit 1 } $oCleanUpManger=$oWSUSServer.GetCleanUpManager() $oCleanUpScope=new-object Microsoft.UpdateServices.Administration.CleanupScope $oCleanUpScope.DeclineSupersededUpdates=$true $oCleanUpScope.DeclineExpiredUpdates=$true $oCleanUpScope.CleanupUnneededContentFiles=$true $oCleanUpScope.CleanupLocalPublishedContentFiles=$true $oCleanUpScope.CleanupObsoleteUpdates=$false $oCleanUpScope.CompressUpdates=$false $oCleanUpScope.CleanupObsoleteComputers=$false $oCleanUpManger.PerformCleanup($oCleanUpScope)