From 6d942620c7cbf693843ea0998fcd9ee947b88d46 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 19 Aug 2023 16:48:01 +0100 Subject: [PATCH 1/3] making it more again better demo --- developing/Oslo Demo.ps1 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/developing/Oslo Demo.ps1 b/developing/Oslo Demo.ps1 index 82477e7f..8028e5f9 100644 --- a/developing/Oslo Demo.ps1 +++ b/developing/Oslo Demo.ps1 @@ -97,4 +97,13 @@ Start-DbcPowerBi -FromDatabase # then use localhost,7401 tempdb and u:sqladmin p:dbatools.IO -# question turn off a container adn talk about hte fails? \ No newline at end of file +# question turn off a container adn talk about hte fails? + + +## made some funky results for the Power Bi + +$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check Instance, Database -Show $show -legacy $false -PassThru + +$CheckResults | Convert-DbcResult -Label 'DatabaseInstance' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose + +$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check compatibilitylevel -Show $show -legacy $false -PassThru \ No newline at end of file From aa3b2f5af6777889d2b2f57782a025e2f4e223c0 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 19 Aug 2023 16:48:42 +0100 Subject: [PATCH 2/3] 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' From e2072c78d998c71a6db7b4f63c2aec5be2bcef52 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 19 Aug 2023 16:49:12 +0100 Subject: [PATCH 3/3] so that the database checks dont break the PowerBi Add Pester V5 Database Level Checks #884 --- source/checks/Databasev5.Tests.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/checks/Databasev5.Tests.ps1 b/source/checks/Databasev5.Tests.ps1 index 37b002a5..a73d6dc7 100644 --- a/source/checks/Databasev5.Tests.ps1 +++ b/source/checks/Databasev5.Tests.ps1 @@ -216,7 +216,7 @@ Describe "Query Store Disabled" -Tag QueryStoreDisabled, Medium, Database -ForEa Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach $InstancesToTest { $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.compatibilitylevel').Value - Context "Compatibility level matches server compatibility level" { + Context "Compatibility level matches server compatibility level on <_.Name>" { 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 } } { $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." } @@ -226,7 +226,7 @@ Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -ForEach $InstancesToTest { $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.guestuserconnect').Value - Context "Testing Guest user has CONNECT permission" { + Context "Testing Guest user has CONNECT permission on <_.Name>" { 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 } } { $psitem.GuestUserConnect | Should -BeFalse -Because "we don't want the guest user to have connect access to our database." } @@ -236,7 +236,7 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest { $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value - Context "Testing Recovery Model" { + Context "Testing Recovery Model on <_.Name>" { 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 } } { $psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model." } @@ -246,7 +246,7 @@ Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $I Describe "PseudoSimple Recovery Model" -Tag PseudoSimple, Medium, Database -ForEach $InstancesToTest { $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.pseudosimple').Value - Context "Testing database is not in PseudoSimple recovery model" { + Context "Testing database is not in PseudoSimple recovery model on <_.Name>" { 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' } } { $psitem.PseudoSimple | Should -BeFalse -Because "PseudoSimple means that a FULL backup has not been taken and the database is still effectively in SIMPLE mode" } @@ -256,7 +256,7 @@ Describe "PseudoSimple Recovery Model" -Tag PseudoSimple, Medium, Database -ForE Describe "Contained Database Auto Close" -Tag ContainedDBAutoClose, CIS, Database -ForEach $InstancesToTest { $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.containedbautoclose').Value - Context "Testing contained database auto close option" { + Context "Testing contained database auto close option on <_.Name>" { 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" } } { $psitem.ContainedDbAutoClose | Should -BeFalse -Because "Contained Databases should have auto close set to false for CIS compliance." } @@ -268,7 +268,7 @@ Describe "Contained Database SQL Authenticated Users" -Tag ContainedDBSQLAuth, C #if ($version -lt 13 ) { $skip = $true } - Context "Testing contained database to see if sql authenticated users exist" { + Context "Testing contained database to see if sql authenticated users exist on <_.Name>" { 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" } } { $psitem.ContainedDbSqlAuthUsers | Should -Be 0 -Because "We expect there to be no sql authenticated users in contained database." }