Friday, October 22, 2010

Automate the WSUS 3.0 cleanup process using PowerShell.

If you have WSUS setup to use an express version of SQL, you will need to run the cleanup process regularly. You can kick it off manually by opening the "Windows Update Servies" MMC and going to "Options" then "Server Cleanup Wizard". The first time you run it, it may take a while to complete. Use this script and schedule it to automate. Check here for details. http://gallery.technet.microsoft.com/ScriptCenter/en-us/fd39c7d4-05bb-4c2d-8a99-f92ca8d08218

Here is text from the article:

"This script performs the cleanup tasks done by the WSUS cleanup wizard. Because it is a script, it can be automated (for example, via the Windows Task Scheduler). It also provides extended support for computer cleanup, allowing one to specify the number of days of not hearing from the computer before cleanup (default is 30 days), and to optionally skip deletion of computers that are still in Active Directory Directory Services (to avoid accidently removing computers that are still around but having trouble contacting the server). We recommend also performing SQL defragmentation sample script as part of WSUS cleanup.
This script will run on any machine on which both Windows PowerShell and WSUS are installed. This script must be run from an account that has administration rights to the WSUS server. This script can also be adapted to run from a remote machine which has Windows PowerShell and the WSUS remote console installed changing the GetUpdateServer() call to GetUpdateServer(servername, true|false), where servername is the name of the remote WSUS server, and true|false refers to the use of SSL to make the connection. This script takes awhile to run, so be patient."


PowerShell
[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); 

No comments:

Disclaimer

All data and information provided on this site is for informational purposes only. adminbromo.blogspot.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis.