WSUS Cleanup Job on Server 2012

There are POSH CMD-lets ready to use for a Cleanup job, to automate the “Server Cleanup Wizard”
Some additional Informations can be found here:

You can do this for all your SCCM Servers there using WSUS on it with Compliance Setting or in the OS Sheduled Task.

Let me show you how simple it is:

Use the Command:

Get-Command –Module UpdateServices

You see this list:

CommandType     Name                                               Source
-----------     ----                                               ------
Cmdlet          Add-WsusComputer                                   UpdateServices
Cmdlet          Approve-WsusUpdate                                 UpdateServices
Cmdlet          Deny-WsusUpdate                                    UpdateServices
Cmdlet          Get-WsusClassification                             UpdateServices
Cmdlet          Get-WsusComputer                                   UpdateServices
Cmdlet          Get-WsusProduct                                    UpdateServices
Cmdlet          Get-WsusServer                                     UpdateServices
Cmdlet          Get-WsusUpdate                                     UpdateServices
Cmdlet          Invoke-WsusServerCleanup                           UpdateServices
Cmdlet          Set-WsusClassification                             UpdateServices
Cmdlet          Set-WsusProduct                                    UpdateServices
Cmdlet          Set-WsusServerSynchronization                      UpdateServices

You See the invoke-WsusServerCleanup:

PS C:\> get-help Invoke-WsusServerCleanup


    Invoke-WsusServerCleanup [-UpdateServer <IUpdateServer>] [-CleanupObsoleteComputers] [-CleanupObsoleteUpdates]
    [-CleanupUnneededContentFiles] [-CompressUpdates] [-DeclineExpiredUpdates] [-DeclineSupersededUpdates] [-WhatIf]
    [-Confirm]  [<CommonParameters>]


    Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
        -- To download and install Help files for the module that includes this cmdlet, use Update-Help.

the command are simple, first connect to the WSUS-Server and run the cleanup with your options.

Set-ExecutionPolicy unrestricted -force

Get-WsusServer -Name <WSUS-ServerName> -PortNumber 8530

Get-WsusServer | Invoke-WsusServerCleanup –CleanupObsoleteUpdates -CleanupUnneededContentFiles -CompressUpdates -DeclineExpiredUpdates -DeclineSupersededUpdates

Save that Script in D:\WSUS-Script as WSUS-Cleanup.ps1

That can run a long time on the first Use, be careful don’t brake it, it runs a long time Zwinkerndes Smiley

Set the Task Scheduler:




Have Fun, test it before use it in Production, the information’s are “as is”


Leave a Reply


Get every new post delivered to your Inbox

Join other followers:

%d bloggers like this:
Skip to toolbar