awarre / Optimize-WsusServer

Comprehensive Windows Server Update Services (WSUS) cleanup, optimization, maintenance, and configuration PowerShell script.
https://github.com/awarre/Optimize-WsusServer
MIT License
310 stars 65 forks source link

WSUS DB Optimization Fails #22

Open amurbain opened 8 months ago

amurbain commented 8 months ago

Hello!

When running the script with -FirstRun flag and running the optimizations, I'm getting the following error when it approaches the WSUS database optimizations:

Creating custom indexes in WSUS index if they don't already exist. This will speed up future database optimizations.
Invoke-Sqlcmd : A connection was successfully established with the server, but then an error occurred during the login
process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)
At C:\Scripts\Optimize-WsusServer-master\Optimize-WsusServer.ps1:440 char:5
+     Invoke-Sqlcmd -query $createCustomIndexesSQLQuery -ServerInstance ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd : Incorrect syntax was encountered while parsing 'IF 0 = (SELECT COUNT(*) as index_count'.
At C:\Scripts\Optimize-WsusServer-master\Optimize-WsusServer.ps1:440 char:5
+     Invoke-Sqlcmd -query $createCustomIndexesSQLQuery -ServerInstance ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], BatchParserException
    + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Running WSUS SQL database maintenence script. This can take an extremely long time on the first run.
Invoke-Sqlcmd : A connection was successfully established with the server, but then an error occurred during the login
process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)
At C:\Scripts\Optimize-WsusServer-master\Optimize-WsusServer.ps1:444 char:5
+     Invoke-Sqlcmd -query $wsusDBMaintenanceSQLQuery -ServerInstance $ ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
    + FullyQualifiedErrorId : SqlExceptionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Invoke-Sqlcmd : Incorrect syntax was encountered while parsing 'SET NOCOUNT ON;'.
At C:\Scripts\Optimize-WsusServer-master\Optimize-WsusServer.ps1:444 char:5
+     Invoke-Sqlcmd -query $wsusDBMaintenanceSQLQuery -ServerInstance $ ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ParserError: (:) [Invoke-Sqlcmd], BatchParserException
    + FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

Not sure what to do here. Thoughts?

solskogen commented 8 months ago

There's a pull request for this problem. Take a look at https://github.com/awarre/Optimize-WsusServer/pull/19 for the solution.