WSUS cleanup - timeout when deleting "unneeded update files"

20,712

This script is old, but I've had good luck running it on my WSUS server. I inherited one that was completely out of control and the console would crash at various places. I also run this reindex WSUS database script as well, which might help.

I've been running these as nightly maintenance ever since.

Share:
20,712

Related videos on Youtube

slagjoeyoco
Author by

slagjoeyoco

Updated on September 18, 2022

Comments

  • slagjoeyoco
    slagjoeyoco over 1 year

    Performing WSUS cleanup which hasn't been done for quite a while - running the cleanup-wizard with the only selected option being "unneeded update files":

    enter image description here

    After about three minutes of processing, the wizard crashed due to a timeout-exception: enter image description here

    This is the message I press "copy to clipboard" in the console:

    The WSUS administration console was unable to connect to the WSUS Server via the remote API. 
    
    Verify that the Update Services service, IIS and SQL are running on the server. If the problem persists, try restarting IIS, SQL, and the Update Services Service.
    
    System.Net.WebException -- The operation has timed out
    
    Source System.Windows.Forms
    
    Stack Trace:
    at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
    at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
    at Microsoft.UpdateServices.UI.SnapIn.Wizards.ServerCleanup.ServerCleanupWizard.OnCleanupComplete(Object sender, PerformCleanupCompletedEventArgs e)
    

    ...tried the same thing in an elevated instance of PowerShell: enter image description here


    What I have tried so far:

    • Since the timeout period appears to be ~3mins I have set the connection timeout of the Wsus-Site in IIS from 180sec to 10800sec: enter image description here

    • made sure the Account associated with the IIS-ApplicationPool has sufficient permissions on the WSUSContent folder

    • made sure the account I'm running the wizward/script is a member in the WSUS administrators group (and administrators group of the server)

    • disabled the query timeout on the SQL-Server my SUSDB is running on (originally did this while cleaning unused updates and update revisions)

    All other WSUS cleanup steps are working - initially I had a few hiccups while cleaning "unused updates and update revisions" as the cleanup hadn't been performed for a long time. However, after manually deleting a few updates from the database and disabling the timeout that step completed without errors. I should also mention the WSUS server is part of an SCCM-environment and it's managed by our SUP (cleanup on scheduled update sync is enabled).

    Looking around the forums I've found several helpful threads dealing with timeouts while cleaning up "unused updates and update files", but I have not found much about the same problem while cleaning "unneeded update files". So any help would be appreciated here.

    • Am_I_Helpful
      Am_I_Helpful over 6 years
      Click on copy error to clipboard and please share the complete exception stack trace.
    • slagjoeyoco
      slagjoeyoco over 6 years
      @Am_I_Helpful I've edited my question to include the stacktrace I get when pressing "copy to clipboard" in the console.
  • slagjoeyoco
    slagjoeyoco over 6 years
    thank you for this script - I ran it yesterday and discovered today that it actually ran through, including phase 2 (unneeded update files only). What struck me as strange is that it listet 0 disk space freed. So I tried to run it again just out of curiosity and now it keeps failing with the same timeout-exception during phase 2.
  • rejohnson
    rejohnson about 4 years
    Thanks so much. Our problem was the default timeout of 180. Increased it to 10800 as well and now no errors and the cleanup can complete.
  • Ronald Hirth
    Ronald Hirth almost 3 years
    Attention! This link contains a Virus detected by Sophos! This script is old, ,,,,
  • duct_tape_coder
    duct_tape_coder over 2 years
    And now both scripts are dead links. This is why things should be included on the page and not just linked to.