Skip to content

Commit aa3b2f5

Browse files
so that the instance checks dont break Add Pester V5 Instance Level Checks #882
1 parent 6d94262 commit aa3b2f5

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,42 @@ function NewGet-AllInstanceInfo {
507507
}
508508

509509
'SqlEngineServiceAccount' {
510-
$EngineAccounts = Get-DbaService -ComputerName $psitem -Type Engine -ErrorAction SilentlyContinue
511510
$starttype = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.instance.sqlenginestart' }).Value
512511
$state = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.instance.sqlenginestate' }).Value
512+
try {
513+
$EngineAccounts = Get-DbaService -ComputerName $psitem -Type Engine -ErrorAction Stop
514+
515+
} catch [System.Exception] {
516+
if ($_.Exception.Message -like '*No services found in relevant namespaces*') {
517+
$EngineAccounts = [PSCustomObject]@{
518+
InstanceName = $Instance.Name
519+
State = 'unknown'
520+
ExpectedState = $state
521+
StartType = 'unknown'
522+
ExpectedStartType = $starttype
523+
because = 'Some sort of failure - No services found in relevant namespaces'
524+
}
525+
} else {
526+
$EngineAccounts = [PSCustomObject]@{
527+
InstanceName = $Instance.Name
528+
State = 'unknown'
529+
ExpectedState = $state
530+
StartType = 'unknown'
531+
ExpectedStartType = $starttype
532+
because = 'Some sort of failure'
533+
}
534+
}
535+
} catch {
536+
$EngineAccounts = [PSCustomObject]@{
537+
InstanceName = $Instance.Name
538+
State = 'unknown'
539+
ExpectedState = $state
540+
StartType = 'unknown'
541+
ExpectedStartType = $starttype
542+
because = 'We Could not Connect to $Instance $ComputerName , $InstanceName from catch'
543+
}
544+
}
545+
513546
if ($Instance.IsClustered) {
514547
$starttype = 'Manual'
515548
$because = 'This is a clustered instance and Clustered Instances required that the SQL engine service is set to manual'

0 commit comments

Comments
 (0)