From aa3b2f5af6777889d2b2f57782a025e2f4e223c0 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 19 Aug 2023 16:48:42 +0100 Subject: [PATCH] so that the instance checks dont break Add Pester V5 Instance Level Checks #882 --- .../functions/NewGet-AllInstanceInfo.ps1 | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source/internal/functions/NewGet-AllInstanceInfo.ps1 b/source/internal/functions/NewGet-AllInstanceInfo.ps1 index 4b85b0a5..d6c5a16f 100644 --- a/source/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/source/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -507,9 +507,42 @@ function NewGet-AllInstanceInfo { } 'SqlEngineServiceAccount' { - $EngineAccounts = Get-DbaService -ComputerName $psitem -Type Engine -ErrorAction SilentlyContinue $starttype = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.instance.sqlenginestart' }).Value $state = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.instance.sqlenginestate' }).Value + try { + $EngineAccounts = Get-DbaService -ComputerName $psitem -Type Engine -ErrorAction Stop + + } catch [System.Exception] { + if ($_.Exception.Message -like '*No services found in relevant namespaces*') { + $EngineAccounts = [PSCustomObject]@{ + InstanceName = $Instance.Name + State = 'unknown' + ExpectedState = $state + StartType = 'unknown' + ExpectedStartType = $starttype + because = 'Some sort of failure - No services found in relevant namespaces' + } + } else { + $EngineAccounts = [PSCustomObject]@{ + InstanceName = $Instance.Name + State = 'unknown' + ExpectedState = $state + StartType = 'unknown' + ExpectedStartType = $starttype + because = 'Some sort of failure' + } + } + } catch { + $EngineAccounts = [PSCustomObject]@{ + InstanceName = $Instance.Name + State = 'unknown' + ExpectedState = $state + StartType = 'unknown' + ExpectedStartType = $starttype + because = 'We Could not Connect to $Instance $ComputerName , $InstanceName from catch' + } + } + if ($Instance.IsClustered) { $starttype = 'Manual' $because = 'This is a clustered instance and Clustered Instances required that the SQL engine service is set to manual'