Skip to content

Instantly share code, notes, and snippets.

@vjt
Created June 12, 2013 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vjt/5770034 to your computer and use it in GitHub Desktop.
Save vjt/5770034 to your computer and use it in GitHub Desktop.
WSUS Cleanup Script that logs to the Windows Event Log
# Performs a cleanup of WSUS and writes to a custom "WSUS Cleanup" log
# You must create the Event Log using
#
# New-EventLog -LogName "WSUS Cleanup" -Source "Script"
#
# the first time you run this script.
# PowerShell 2.0 required.
#
# - vjt@openssl.it (feeling dirty)
#
Function log($message) {
$message = $message | Out-String
Write-EventLog -LogName "WSUS Cleanup" -Message $message -Source "Script" -EntryType Information -EventId 0
}
log "WSUS Cleanup Started"
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null
$scope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
$scope.DeclineSupersededUpdates = $true;
$scope.DeclineExpiredUpdates = $true;
$scope.CleanupObsoleteUpdates = $true;
$scope.CompressUpdates = $true;
$scope.CleanupObsoleteComputers = $true;
$scope.CleanupUnneededContentFiles = $true;
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$result = $wsus.GetCleanupManager().PerformCleanup($scope);
log $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment