This script will automatically run the “WSUS Server Cleanup Wizard”
This can be added to a scheduled task.
#Region VARIABLES # WSUS Connection Parameters: ## Change settings below to your situation. ## # FQDN of the WSUS server [String]$parentServer = "UK-SVS-WSUS01" # Use secure connection $True or $False [Boolean]$useSecureConnection = $False [Int32]$portNumber = 8530 # From address of email notification [String]$emailFromAddress = "UK-SVS-WSUS01@domain.com" # To address of email notification [String]$emailToAddress = "WSUS Cleanup Results: UK-SVS-WSUS01" # Subject of email notification [String]$emailSubject = "UK-SVS-WSUS01@domain.com" # Exchange server [String]$emailMailserver = "smtp.domain.com" # Cleanup Parameters: ## Set to $True or $False ## # Decline updates that have not been approved for 30 days or more, are not currently needed by any clients, and are superseded by an aproved update. [Boolean]$supersededUpdates = $True # Decline updates that aren't approved and have been expired my Microsoft. [Boolean]$expiredUpdates = $True # Delete updates that are expired and have not been approved for 30 days or more. [Boolean]$obsoleteUpdates = $True # Delete older update revisions that have not been approved for 30 days or more. [Boolean]$compressUpdates = $True # Delete computers that have not contacted the server in 30 days or more. [Boolean]$obsoleteComputers = $True # Delete update files that aren't needed by updates or downstream servers. [Boolean]$unneededContentFiles = $True #EndRegion VARIABLES #Region SCRIPT # Load .NET assembly [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration"); # Connect to WSUS Server $wsusParent = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($parentServer,$useSecureConnection,$portNumber); # Log the date first $DateNow = Get-Date # Perform Cleanup $Body += "$parentServer ($DateNow ) :" | Out-String $CleanupManager = $wsusParent.GetCleanupManager(); $CleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope($supersededUpdates,$expiredUpdates,$obsoleteUpdates,$compressUpdates,$obsoleteComputers,$unneededContentFiles); $Body += $CleanupManager.PerformCleanup($CleanupScope) | Out-String # Send the results in an email Send-MailMessage -From $emailFromAddress -To $emailToAddress -Subject $emailSubject -Body $Body -SmtpServer $emailMailserver #EndRegion SCRIPT |