From LedHed's Wiki
Jump to: navigation, search
Line 6: Line 6:
 
Run this PowerShell script as a Scheduled Task to keep your WSUS server slim and trim.
 
Run this PowerShell script as a Scheduled Task to keep your WSUS server slim and trim.
  
  [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null  
+
# Performs a cleanup of WSUS.
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
+
# Outputs the results to a text file.
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
+
# Adapted and tested by BigTeddy
$cleanupScope.DeclineSupersededUpdates = $true
+
# 3 July 2012
$cleanupScope.DeclineExpiredUpdates = $true
+
   
$cleanupScope.CleanupObsoleteUpdates = $true
+
$outFilePath = '.\wsusClean.txt'
$cleanupScope.CompressUpdates = $true
+
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
#$cleanupScope.CleanupObsoleteComputers = $true
+
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$cleanupScope.CleanupUnneededContentFiles = $true
+
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope;
$cleanupManager = $wsus.GetCleanupManager();
+
$cleanupScope.DeclineSupersededUpdates = $true
$cleanupManager.PerformCleanup($cleanupScope);
+
$cleanupScope.DeclineExpiredUpdates = $true
 +
$cleanupScope.CleanupObsoleteUpdates = $true
 +
$cleanupScope.CompressUpdates = $true
 +
#$cleanupScope.CleanupObsoleteComputers = $true
 +
$cleanupScope.CleanupUnneededContentFiles = $true
 +
$cleanupManager = $wsus.GetCleanupManager();
 +
$cleanupManager.PerformCleanup($cleanupScope) | Out-File -FilePath $outFilePath
 +
 
 
NOTE: All credit for this script goes to "The Scripting Guys" at MS TechNet. See references section for link to original script.
 
NOTE: All credit for this script goes to "The Scripting Guys" at MS TechNet. See references section for link to original script.
  

Revision as of 00:56, 29 January 2013

Overview

WSUS can be a life saver, but with the large volume of updates that are put out from Microsoft, WSUS can grow out of control quite easily. To keep it under control you need to run the "WSUS cleanup wizard" periodically to keep things in good running order.


Cleanup Script

Run this PowerShell script as a Scheduled Task to keep your WSUS server slim and trim.

  1. Performs a cleanup of WSUS.
  2. Outputs the results to a text file.
  3. Adapted and tested by BigTeddy
  4. 3 July 2012

$outFilePath = '.\wsusClean.txt' [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer(); $cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope; $cleanupScope.DeclineSupersededUpdates = $true $cleanupScope.DeclineExpiredUpdates = $true $cleanupScope.CleanupObsoleteUpdates = $true $cleanupScope.CompressUpdates = $true

  1. $cleanupScope.CleanupObsoleteComputers = $true

$cleanupScope.CleanupUnneededContentFiles = $true $cleanupManager = $wsus.GetCleanupManager(); $cleanupManager.PerformCleanup($cleanupScope) | Out-File -FilePath $outFilePath

NOTE: All credit for this script goes to "The Scripting Guys" at MS TechNet. See references section for link to original script.


References

http://gallery.technet.microsoft.com/ScriptCenter/fd39c7d4-05bb-4c2d-8a99-f92ca8d08218/