WSUS | Saving Windows Disk Space | Scheduled “Server Cleanup Wizard”

This script will automatically run the “WSUS Server Cleanup Wizard”
This can be added to a scheduled task.

# 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 = ""
# To address of email notification
[String]$emailToAddress = "WSUS Cleanup Results: UK-SVS-WSUS01"
# Subject of email notification
[String]$emailSubject = ""
# Exchange server
[String]$emailMailserver = ""
# 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
#Region SCRIPT
# Load .NET assembly
# 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.