Forum Discussion

Taff4Ever's avatar
Taff4Ever
Copper Contributor
Mar 22, 2023

PowerShell Novice: Script Timeout #WSUS

Hi

 

I'm an idiot.  Have to say this at the beginning so you are ready to help a moron understand what is happening!!!  And in plain English, or crayon......

 

I'm trying to schedule a PowerShell script to clean up my WSUS which is proving to be a pain to keep on top of.......little bit of research and I find the following basic script which appears to do what I need, however I get a red warning that this basically times out and then fails in its task.

 

Is my script too basic and I am expecting too much, or can the time frame be increased to allow it to do what it needs to do?!  I don't want to pay for the infamous AdamJ script and had hoped WSUS would be developed further by now to accommodate such cleaning tasks....but hey ho!

 

Any help would be most welcome...thanks!!

 

Get-Date >> E:\WSUS_Logs\WSUS_Decline.txt
Get-WsusServer | Invoke-WsusServerCleanup -DeclineExpiredUpdates -DeclineSupersededUpdates >>E:\WSUS_Logs\WSUS_Decline.txt

and a second script for the following

 

Get-Date >> E:\WSUS_Logs\WSUS_Cleanup.txt
Get-WsusServer | Invoke-WsusServerCleanup -CleanupObsoleteComputers -CleanupObsoleteUpdates -CleanupUnneededContentFiles >>E:\WSUS_Logs\WSUS_Cleanup.txt

 

7 Replies

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    Taff4Ever 

     

    For many years now, WSUS performance has suffered from missing indexes out-of-the-box.

     

    The System Center product group have for a long time now published a guide on how you can add these missing indexes to the WSUS database. Speaking from experience, this advice from the product is a "must do" post installation task as the performance difference is profound.

     

    Here's the documentation where you can find the T-SQL script in step 3:

     

     

    Cheers,

    Lain

    • Taff4Ever's avatar
      Taff4Ever
      Copper Contributor
      Thanks for the info and of course Google has given me some ideas on this, but my issues is what I should be adding to the script and where it should be.

      I can’t seem to find a way to ensure there is no timeout for this as much of what I’ve read shows a specific time frame and wondered if it was possible.

      I’m a complete novice with this so appreciate any feedback
      • LainRobertson's avatar
        LainRobertson
        Silver Contributor

        Taff4Ever 

         

        You can't change the script, unfortunately.

         

        The error itself is an SQL error, and you have no capacity for controlling the query timeout.

         

        But by applying the indexes from the above article, you improve SQL performance on the WSUS database quite considerably (for certain functions), which greatly shortens the time it takes to finish, which in turn resolves this error condition.

         

        In other words, you can't tackle this from the client side. You need to address it from the database server side.

         

        Cheers,

        Lain

  • Alex_Rechs's avatar
    Alex_Rechs
    Copper Contributor
    Hi,
    It could be not an answer you desire, but I found a lot of workaround when googled the following:
    "Invoke-WsusServerCleanup" timeout

Resources