(2 intermediate revisions by the same user not shown) | |||
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. |
+ | Outputs the results to a text file. | ||
+ | Adapted and tested by BigTeddy | ||
+ | 3 July 2012 | ||
+ | |||
+ | $outFilePath = '.\wsusClean.txt' | ||
+ | [reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null | ||
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer(); | $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer(); | ||
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope; | $cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope; | ||
Line 16: | Line 22: | ||
$cleanupScope.CleanupUnneededContentFiles = $true | $cleanupScope.CleanupUnneededContentFiles = $true | ||
$cleanupManager = $wsus.GetCleanupManager(); | $cleanupManager = $wsus.GetCleanupManager(); | ||
− | $cleanupManager.PerformCleanup($cleanupScope) | + | $cleanupManager.PerformCleanup($cleanupScope) | Out-File -FilePath $outFilePath |
− | NOTE: All credit for this script goes to " | + | |
+ | NOTE: All credit for this script goes to "BigTeddy". You can see his original TechNet post in the references section. | ||
+ | |||
+ | |||
+ | === PowerShell === | ||
+ | Before you can run this script as a Scheduled Task you need to do a few things: | ||
+ | # Save it as a file with a .PS1 extension | ||
+ | # Enable Script Execution by running the following command from within PowerShell | ||
+ | Set-ExecutionPolicy RemoteSigned | ||
+ | |||
+ | Also when you setup the task run it like this: | ||
+ | powershell.exe C:\Scripts\WSUS-Cleanup.ps1 | ||
+ | You need to pass the full path to the .PS1 file.<br> | ||
+ | It also has to be run with elevated privileges. | ||
== References == | == References == | ||
− | http://gallery.technet.microsoft.com/ | + | http://gallery.technet.microsoft.com/scriptcenter/WSUS-Clean-Powershell-102f8fc6 |
Latest revision as of 01:25, 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.
Performs a cleanup of WSUS. Outputs the results to a text file. Adapted and tested by BigTeddy 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 #$cleanupScope.CleanupObsoleteComputers = $true $cleanupScope.CleanupUnneededContentFiles = $true $cleanupManager = $wsus.GetCleanupManager(); $cleanupManager.PerformCleanup($cleanupScope) | Out-File -FilePath $outFilePath
NOTE: All credit for this script goes to "BigTeddy". You can see his original TechNet post in the references section.
PowerShell
Before you can run this script as a Scheduled Task you need to do a few things:
- Save it as a file with a .PS1 extension
- Enable Script Execution by running the following command from within PowerShell
Set-ExecutionPolicy RemoteSigned
Also when you setup the task run it like this:
powershell.exe C:\Scripts\WSUS-Cleanup.ps1
You need to pass the full path to the .PS1 file.
It also has to be run with elevated privileges.
References
http://gallery.technet.microsoft.com/scriptcenter/WSUS-Clean-Powershell-102f8fc6