Skip to content

Commit 7637efe

Browse files
Merge pull request #1001 from dataplat/instancecheckscontinued
some database check fixes #884 and instance ~882
2 parents f5b3d08 + e2072c7 commit 7637efe

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

developing/Oslo Demo.ps1

+10-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,13 @@ Start-DbcPowerBi -FromDatabase
9797

9898
# then use localhost,7401 tempdb and u:sqladmin p:dbatools.IO
9999

100-
# question turn off a container adn talk about hte fails?
100+
# question turn off a container adn talk about hte fails?
101+
102+
103+
## made some funky results for the Power Bi
104+
105+
$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check Instance, Database -Show $show -legacy $false -PassThru
106+
107+
$CheckResults | Convert-DbcResult -Label 'DatabaseInstance' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose
108+
109+
$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check compatibilitylevel -Show $show -legacy $false -PassThru

source/checks/Databasev5.Tests.ps1

+6-6
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Describe "Query Store Disabled" -Tag QueryStoreDisabled, Medium, Database -ForEa
216216
Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach $InstancesToTest {
217217
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.compatibilitylevel').Value
218218

219-
Context "Compatibility level matches server compatibility level" {
219+
Context "Compatibility level matches server compatibility level on <_.Name>" {
220220
It "Database <_.Name> has the expected compatibility level on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.compatexclude -notcontains $psitem.Name } } {
221221
$psitem.CompatibilityLevel | Should -Be $psitem.ServerLevel -Because "it means you are on the appropriate compatibility level for your SQL Server version to use all available features."
222222
}
@@ -226,7 +226,7 @@ Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach
226226
Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -ForEach $InstancesToTest {
227227
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.guestuserconnect').Value
228228

229-
Context "Testing Guest user has CONNECT permission" {
229+
Context "Testing Guest user has CONNECT permission on <_.Name>" {
230230
It "Database Guest user should return no CONNECT permissions in <_.Name> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.guestuserexclude -notcontains $psitem.Name } } {
231231
$psitem.GuestUserConnect | Should -BeFalse -Because "we don't want the guest user to have connect access to our database."
232232
}
@@ -236,7 +236,7 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo
236236
Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest {
237237
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value
238238

239-
Context "Testing Recovery Model" {
239+
Context "Testing Recovery Model on <_.Name>" {
240240
It "Database <_.Name> should be set to <_.ConfigValues.recoverymodeltype> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.recoverymodelexclude -notcontains $psitem.Name } } {
241241
$psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model."
242242
}
@@ -246,7 +246,7 @@ Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $I
246246
Describe "PseudoSimple Recovery Model" -Tag PseudoSimple, Medium, Database -ForEach $InstancesToTest {
247247
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.pseudosimple').Value
248248

249-
Context "Testing database is not in PseudoSimple recovery model" {
249+
Context "Testing database is not in PseudoSimple recovery model on <_.Name>" {
250250
It "Database <_.Name> has PseudoSimple recovery model equal false on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database -and $_.RecoveryModel -eq 'Full' } else { $psitem.ConfigValues.pseudosimpleexclude -notcontains $psitem.Name -and $_.RecoveryModel -eq 'Full' } } {
251251
$psitem.PseudoSimple | Should -BeFalse -Because "PseudoSimple means that a FULL backup has not been taken and the database is still effectively in SIMPLE mode"
252252
}
@@ -256,7 +256,7 @@ Describe "PseudoSimple Recovery Model" -Tag PseudoSimple, Medium, Database -ForE
256256
Describe "Contained Database Auto Close" -Tag ContainedDBAutoClose, CIS, Database -ForEach $InstancesToTest {
257257
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.containedbautoclose').Value
258258

259-
Context "Testing contained database auto close option" {
259+
Context "Testing contained database auto close option on <_.Name>" {
260260
It "Database <_.Name> should have auto close set to false on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database -and $_.ContainmentType -ne "NONE" } else { $psitem.ConfigValues.contdbautocloseexclude -notcontains $psitem.Name -and $_.ContainmentType -ne "NONE" } } {
261261
$psitem.ContainedDbAutoClose | Should -BeFalse -Because "Contained Databases should have auto close set to false for CIS compliance."
262262
}
@@ -268,7 +268,7 @@ Describe "Contained Database SQL Authenticated Users" -Tag ContainedDBSQLAuth, C
268268

269269
#if ($version -lt 13 ) { $skip = $true }
270270

271-
Context "Testing contained database to see if sql authenticated users exist" {
271+
Context "Testing contained database to see if sql authenticated users exist on <_.Name>" {
272272
It "Database <_.Name> should have no sql authenticated users on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database -and $_.ContainmentType -ne "NONE" } else { $psitem.ConfigValues.contdbsqlauthexclude -notcontains $psitem.Name -and $_.ContainmentType -ne "NONE" } } {
273273
$psitem.ContainedDbSqlAuthUsers | Should -Be 0 -Because "We expect there to be no sql authenticated users in contained database."
274274
}

source/internal/functions/NewGet-AllInstanceInfo.ps1

+34-1
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)