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)
1,168 times
Add to favorites
Windows Update
3/2/2018
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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!