How To Clean Up WSUS

I recently added Windows 10 to my WSUS Product and Classifications and got very surprised by the 100 GB of updates that was queued for download! Let’s learn how to clean up WSUS content folder.

Unfortunately, cancelling the download queued is not that straight forward, so I decided to use the opportunity to clean up my WSUS content folder and reclaim my VMFS datastore at the same time.

The reason why the updates where 100 GB was because I had all Classifications selected and an Automatic Approval Rule! After the changes below the updates where only 1 GB.

Lesson Learned, Be Careful with Automatic Approval Rules…

Clean Up WSUS

Clean Up WSUS 01

Before you start make sure to disable your Automatic Approval Rule(s). I have a very nice script below that saved me 300% of downloads.

Clean Up WSUS 02

It’s also a good time to verify that only the Products and Languages you actually need are selected.

From Update Files and Languages, make sure that you don’t have Express installation files selected.

Clean Up WSUS 03

Let’s clean up WSUS by running the following commands:

Take a look in Task Manager and you’ll see that the process “SQL Server Windows NT – 64 bit” is consuming all the CPU. This is because all database tables are being checked and any missing hotfixes are being marked for download.

This could take up to 30-60 minutes to complete, depending on the Products and Classifications you have. When the CPU drops you’re ready to proceed.

Let’s start Synchronization.

Clean Up WSUS 07

The thing with WSUS is that it’s going to download everything, even superseded updates. Now the purpose of this post is to also reclaim VMFS storage, so downloading all and then deleting them won’t help much. Luckily there’s a script for that.

Clean Up WSUS 09

WOW! Do you belive that? Out of 6467 updates, 4179 where declined.

Now run the Automatic Approval Rule to start the downloads.

Clean Up WSUS 10

Many people might argue that is unnecessary to run the wsusutil.exe reset command, simply because all updates will be re-downloaded.

Well, you could always search and decline all updates you don’t want and then run the Server Cleanup Wizard, but its PITA.

My WSUS folder went from 75 GB to 20 GB so I’m happy.

Reclaim VMFS Datastore

I’m not sure if you’re aware, but when you’re using Thin Provisioning it doesn’t matter if you delete unwanted files. When the space has been alllocated it will stay that way until you do the following steps below.

My WSUS folder was located on C: then moved to D: and finally E:

To reclaim the space after all unnecessary files has been deleted run sDelete on all volumes.

When finished shutdown the VM and connect to your ESXi host through Putty.

Navigate to your VMFS datastore folder for that VM.

Now run the following command for all disks:

Clean Up WSUS 04

Power up the VM and enjoy. I reclaimed 120 GB in 2 hours on just 1 VM!

Clean Up WSUS 05

Clean Up WSUS 06


37 Responses to How To Clean Up WSUS

  1. Hi
    thanks for the script however my server name has a hyphen “abc-def” and the script errors!

  2. Maybe this is obvious and I’m just being dense, but in the batch file what is the “echo Delete WSUS Folder Content” for? Am I supposed to manually delete this folder and then allow the batch file to continue?

  3. The script to decline the updates keeps failing. Getting this when trying to run it:

    Error Occurred
    Exception Message:
    The specified string is invalid.
    Parameter name: ServerName
    at Microsoft.UpdateServices.Administration.AdminProxy.CreateUpdateServer(Object[] args)
    at CallSite.Target(Closure , CallSite , RuntimeType , Object , Object , Object )

      • Still getting error

        Error Occurred
        Exception Message:
        The specified string is invalid.
        Parameter name: ServerName
        at Microsoft.UpdateServices.Administration.AdminProxy.CreateUpdateServer(Object[] args)
        at Microsoft.UpdateServices.Administration.AdminProxy.GetUpdateServer(String serverName, Boolean useSecureConnection, Int32 portNumber)
        at GetUpdateServer(Object , Object[] )
        at System.Management.Automation.MethodInformation.Invoke(Object target, Object[] arguments)
        at System.Management.Automation.DotNetAdapter.AuxiliaryMethodInvoke(Object target, Object[] arguments, MethodInformation methodInformation, Object[] originalArguments)

  4. Great post used it on a new WSUS setup. Before doing your steps I was it over 300 GB of updates. Redid the sever now only downloading 62 GB. Total Declined Updates: 3690


  5. it should be: “.\WsusUtil.exe reset” otherwise you get an error that it cannot find the program (“mistyped”)

  6. Does the script need to be run from the wsus server itself? or can you run it from another server? i am getting the same errors as Vivek

  7. Hi

    I am getting the below error when running the script:

    Exception calling “GetUpdates” with “1” argument(s): “The operation has timed out”
    At line:1 char:1
    + $u=$updateServer.GetUpdates($updatescope )
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

  8. Any idea why I am getting the above exception when running the script. Your answer is highly appreciated.

  9. I get the below error while running the script in the second box of the page. Any thoughts?

    Error Occurred
    Exception Message:
    Method invocation failed because [System.String] does not contain a method named ‘GetU
    at CallSite.Target(Closure , CallSite , Object , Object )
    at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFra
    me frame)
    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Int
    erpretedFrame frame)

  10. Hi, I cannot run this script normally, after running it about 2-3 mins it returns error, here is my result:

    Error Occurred
    Exception Message:
    要求已經中止: 作業逾時。 <

  11. Hi, I cannot run this script normally, after running it about 2-3 mins it returns error, here is my result:

    Connected sucessfully
    Error Occurred
    Exception Message:
    要求已經中止: 作業逾時。 (it means request has stopped: time out.)
    於 System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request
    於 System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest req
    於 Microsoft.UpdateServices.Internal.DatabaseAccess.ApiRemotingCompressionProxy.GetW
    ebResponse(WebRequest webRequest)
    於 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Ob
    ject[] parameters)
    於 Microsoft.UpdateServices.Internal.ApiRemoting.ExecuteSPSearchUpdates(String updat
    eScopeXml, String preferredCulture, Int32 publicationState)
    於 Microsoft.UpdateServices.Internal.DatabaseAccess.AdminDataAccessProxy.ExecuteSPSe
    archUpdates(String updateScopeXml, String preferredCulture, ExtendedPublicationState p
    於 Microsoft.UpdateServices.Internal.BaseApi.Update.SearchUpdates(UpdateScope search
    Scope, ExtendedPublicationState publicationState, UpdateServer updateServer)
    於 CallSite.Target(Closure , CallSite , Object , Object )

    How can I solve this problem?

      • Nope, no proxy used.
        I try to follow the script, and I found it stopped here.

        $u=$updateServer.GetUpdates($updatescope )

        so, the connection is done, but it cannot get updates?

        I ran this script after stop wsusservice and reset wsus, then start wsusservice, make sure SQL server 64-bit job was stabled. so what may cause timeout? too lower level’s vm? ram? or something?

  12. Ok guys i had the same problem with the dash in the hostname,and made it work with your suggestion to evek.
    Thanks for the great post.

  13. i see a few techs having issues with server name….can you post on how you worked out the problem?

Leave a reply