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


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /homepages/40/d806441738/htdocs/clickandbuilds/edwardsd/work/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

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

Leave a Reply

Your email address will not be published.

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