Optimize and cleanup of WSUS on Windows Server 2012 R2 and 2016

Optimize WSUS DB using official Microsoft SQL script and performs server maintenance. Supports Server 2016 and 2012 R2.

 
 
 
 
 
(0)
3,240 times
Add to favorites
Windows Update
3/2/2018
E-mail Twitter del.icio.us Digg Facebook
  • Errors Found
    3 Posts | Last post November 19, 2019
    • Used script to verify system as I cannot run individual reports without crash and first to DB maintenance options in UI: After running script I got this in error log:
      
      **********************
      Windows PowerShell transcript start
      Start time: 20191106094725
      Username: PMHADLEY\mnaglie
      RunAs User: PMHADLEY\mnaglie
      Machine: WSUS2016 (Microsoft Windows NT 10.0.14393.0)
      Host Application: C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
      Process ID: 4676
      PSVersion: 5.1.14393.3053
      PSEdition: Desktop
      PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.3053
      BuildVersion: 10.0.14393.3053
      CLRVersion: 4.0.30319.42000
      WSManStackVersion: 3.0
      PSRemotingProtocolVersion: 2.3
      SerializationVersion: 1.1.0.1
      **********************
      Transcript started, output file is C:\Temp\Optimize-WSUS\20191106_Optimize-WSUS.log
      PS>TerminatingError(Invoke-WsusServerCleanup): "Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."
      Invoke-WsusServerCleanup : Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation 
      or the server is not responding.
      At C:\Temp\Optimize-WSUS\Optimize-WSUS.ps1:30 char:18
      + ... susServer | Invoke-WsusServerCleanup -CleanupObsoleteComputers -Clean ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidData: (Microsoft.Updat...rCleanupCommand:InvokeWsusServerCleanupCommand) 
      [Invoke-WsusServerCleanup], SqlException
          + FullyQualifiedErrorId : UnexpectedError,Microsoft.UpdateServices.Commands.InvokeWsusServerCleanupCommand
      Invoke-WsusServerCleanup : Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
      At C:\Temp\Optimize-WSUS\Optimize-WSUS.ps1:30 char:18
      + ... susServer | Invoke-WsusServerCleanup -CleanupObsoleteComputers -Clean ...
      
    • Hi!
      You have to extend Timeout for Cleanup-Wizard command:
      First download SQL management studio.
      Connect to SQL via: \\.\pipe\microsoft##WID\tsql\query
      Right click on \\.\pipe\microsoft##WID\tsql\query (first in the row on the left)
      Select Properties
      Select Connections
      Set timeout from default 600 to 0 (= no timeout)
      
    • My WSUS Server uses SQL Server 2016 and I am getting the same "Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding" error.
  • Query
    2 Posts | Last post September 10, 2018
    • How long should this take to run?
      
      Also when i am getting the below error.
      
      Transcript started, output file is C:\PowerShellScripts\20180704_Optimize-WSUS.log
      Obsolete Updates Deleted:0
      Expired Updates Declined: 0
      Obsolete Updates Deleted:0
      Updates Compressed:2397
      Obsolete Computers Deleted:0
      Diskspace Freed:0
      Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to SQL Server.
      The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is
      configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to
      SQL Server)
      At C:\PowerShellScripts\Optimize-WSUS.ps1:31 char:1
      + Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -I ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
          + FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
      
      Invoke-Sqlcmd :
      At C:\PowerShellScripts\Optimize-WSUS.ps1:31 char:1
      + Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query" -I ...
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], ParserException
          + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
      
      Transcript stopped, output file is C:\PowerShellScripts\20180704_Optimize-WSUS.log
      PS SQLSERVER:\>
    • Hi! What version is your Windows Server running?
      
      For 2012/2016 the command is: Invoke-Sqlcmd -ServerInstance "\\.\pipe\microsoft##WID\tsql\query"
      For 2003/2008: Invoke-Sqlcmd -ServerInstance "\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query"
      
      I should change the script to use the right command!