Wsus import основное соединение было закрыто новый сценарий power shell

We have some windows servers where discovery takes 7-8 hrs to complete. Only error I see in the pattern logs are about SQL Server Cluster commands failing as below. Interestingly if we run discovery from different mid server with same ip it gets completed within 5 minutes.  What could be difference between these 2 mids? Network path? Any configuration setting which we needs to validate?

Also even if we some command does not work why it takes so much time declare it failure? As i see most of the commands has 300 seconds timeout value.

We are unable to find out the root cause of this. Please let us know if anyone has experienced the same issue and shed some light.

2024-02-29 23:28:45: Executing WMI query on host: removed original ip with namespace: root/Microsoft/SqlServer and query: SELECT Name FROM __NAMESPACE

2024-02-29 23:28:47: Error during execution of Windows command: executeQuery -Namespace root/Microsoft/SqlServer -Query “SELECT Name FROM __NAMESPACE” due to com.snc.automation_common.integration.exceptions.InvalidCommandException: executeQuery : Could not get query SELECT Name FROM __NAMESPACE on namespace=root/Microsoft/SqlServer. Original Exception: Invalid namespace

At line:1 char:5

+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,executeQuery

2024-02-29 23:28:47: Execution time: 2899 ms

Thanks & Regards,
Amol Kotwal

Basic structure for a PowerShell “application”:

#!/usr/bin/env pwsh
param( [Parameter(Mandatory=$True)] [string] $MandatoryParam, [string] $OptionalParam = '', [switch] $SwitchParam
)
# Stop on every error
$script:ErrorActionPreference = 'Stop'
try { ######################################################################## # # Application code here # ########################################################################
}
catch { function LogError([string] $exception) { Write-Host -ForegroundColor Red $exception } # Type of $_: System.Management.Automation.ErrorRecord # NOTE: According to https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/windows-powershell-error-records # we should always use '$_.ErrorDetails.Message' instead of '$_.Exception.Message' for displaying the message. # In fact, there are cases where '$_.ErrorDetails.Message' actually contains more/better information than '$_.Exception.Message'. if ($_.ErrorDetails -And $_.ErrorDetails.Message) { $unhandledExceptionMessage = $_.ErrorDetails.Message } elseif ($_.Exception -And $_.Exception.Message) { $unhandledExceptionMessage = $_.Exception.Message } else { $unhandledExceptionMessage = 'Could not determine error message from ErrorRecord' } # IMPORTANT: We compare type names(!) here - not actual types. This is important because - for example - # the type 'Microsoft.PowerShell.Commands.WriteErrorException' is not always available (most likely # when Write-Error has never been called). if ($_.Exception.GetType().FullName -eq 'Microsoft.PowerShell.Commands.WriteErrorException') { # Print error messages (without stacktrace) LogError $unhandledExceptionMessage } else { # Print proper exception message (including stack trace) # NOTE: We can't create a catch block for "RuntimeException" as every exception # seems to be interpreted as RuntimeException. if ($_.Exception.GetType().FullName -eq 'System.Management.Automation.RuntimeException') { LogError "$unhandledExceptionMessage$([Environment]::NewLine)$($_.ScriptStackTrace)" } else { LogError "$($_.Exception.GetType().Name): $unhandledExceptionMessage$([Environment]::NewLine)$($_.ScriptStackTrace)" } } exit 1
}