Created
June 12, 2013 23:30
-
-
Save vjt/5770034 to your computer and use it in GitHub Desktop.
WSUS Cleanup Script that logs to the Windows Event Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. | |
# | |
# - [email protected] (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