diff --git a/CHANGELOG.md b/CHANGELOG.md index 729dcbec..60d1a8f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - added pester tests to check that changelog is edited. +### Changed + +- Fix to Invoke-DbcCheck so that tests that have not been converted to v5 produce warning messages. + ## [3.0.1-preview0026] - 2023-08-28 ### Added diff --git a/developing/Oslo Demo.ps1 b/developing/Oslo Demo.ps1 index 8028e5f9..706e5c76 100644 --- a/developing/Oslo Demo.ps1 +++ b/developing/Oslo Demo.ps1 @@ -7,27 +7,32 @@ $containers = $SQLInstances = $dbachecks1, $dbachecks2, $dbachecks3 = 'dbachecks $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password $show = 'All' + +$PSDefaultParameterValues = @{ + "*:SQlInstance" = $SQLInstances + "*:SqlCredential" = $cred +} #endregion #region What do we have? -Get-DbaDatabase -SqlInstance $Sqlinstances -SqlCredential $cred -ExcludeSystem | Select-Object Sqlinstance, DatabaseName, Status +Get-DbaDatabase | Select-Object Sqlinstance, Name, Status -Get-DbaAgentJob -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Name, Enabled +Get-DbaAgentJob | Select-Object Sqlinstance, Name, Enabled #end region -Get-DbaLastBackup -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table +Get-DbaLastBackup | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table # lets run a couple of tests # this one shows that the old existing code will work # the legacy switch is set to true by default -Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show +Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show # So lets show the shiny new faster code - legacy switch set to false -Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false +Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false # The Authentication check failed but we would like to pass - lets set config @@ -35,14 +40,14 @@ Set-DbcConfig -Name policy.connection.authscheme -Value SQL # run again -Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false +Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false # Hmmm, we know that we will never be able to remote onto these containers so let talk about skipping. No Claudio not that sort of skipping!! Set-DbcConfig -Name skip.connection.remoting -Value $true # run again -Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false +Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false # So much quicker !!! OK for one check it will be slower. For two it will probably be about the same but for 3 or more it will be quicker. Much quicket. Exrapolate that to 100 checks and a 1000 instances you can see the difference. @@ -57,7 +62,7 @@ Invoke-PerfAndValidateCheck -Checks $Checks # ok lets run the checks and save the out put to a variable so that we can show you what happens. Notice we need the -PassThru switch -$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru +$CheckResults = Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru # this is our base results object $CheckResults @@ -68,6 +73,7 @@ $SomethingUseful = $CheckResults | Convert-DbcResult $SomethingUseful $SomethingUseful | Format-Table +#TODO: fix this Checking Instance Connection on on dbachecks3 $SomethingUseful | Select-Object -First 1 @@ -87,23 +93,25 @@ code ./oslo.json # or put them into a database table -$CheckResults | Convert-DbcResult -Label 'CoffeeFilter' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose +$CheckResults | Convert-DbcResult -Label 'claudiodidthis' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT * FROM CheckResults' +Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT COUNT(*) FROM CheckResults' +# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!! # YOU CANT DO THIS FROM HERE - Open Windows terminal on the host and run Start-DbcPowerBi -FromDatabase +# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!! # then use localhost,7401 tempdb and u:sqladmin p:dbatools.IO -# question turn off a container adn talk about hte fails? +# question turn off a container and talk about the 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 = Invoke-DbcCheck -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 +$CheckResults = Invoke-DbcCheck -Check compatibilitylevel -Show $show -legacy $false -PassThru \ No newline at end of file diff --git a/developing/Robs-Instance.ps1 b/developing/Robs-Instance.ps1 index 4e37a3d6..0e0bc44f 100644 --- a/developing/Robs-Instance.ps1 +++ b/developing/Robs-Instance.ps1 @@ -23,6 +23,13 @@ $Checks = 'LoginAuditSuccessful', 'LoginAuditFailed' Set-DbcConfig -Name skip.security.PublicPermission -Value $false $Checks = 'PublicRolePermission' $Checks = 'PUblicPermission' +$Checks = 'Database' +$Checks = 'AgentServiceAccount', 'DbaOperator', 'DatabaseMailProfile', 'AgentMailProfile' + +$DatabaseTags = (Get-DbcCheck -Group Database).UniqueTag + +$Checks = $DatabaseTags[1..5] + Invoke-PerfAndValidateCheck -Checks $Checks Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail diff --git a/source/functions/Invoke-DbcCheck.ps1 b/source/functions/Invoke-DbcCheck.ps1 index 218e2bc2..2e3ffeb4 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -374,11 +374,26 @@ function Invoke-DbcCheck { if ($PassThru) { $configuration.Run.PassThru = $true } - # So that if the only check passed in is not yet converted - so that we dont get red. - if ($check -in $notv5) { - Write-PSFMessage -Message "You are running a single check that is not yet converted to v5." -Level Warning + # So that if all of the checks passed in are not yet converted so that we stop + + # Compare the two arrays + $comparisonResult = Compare-Object -ReferenceObject $check -DifferenceObject $notv5 + + # If all elements of $check are in $notv5, then $comparisonResult will be either $null or only contain differences where SideIndicator is '=>' + + if (($comparisonResult | Where-Object SideIndicator -EQ '<=').Count -eq 0) { + $Message = "The checks that you are running are yet to be converted to v5 unfortunately. We cannot continue. Please use the legacy switch" + Write-PSFMessage -Message $Message -Level Warning Return } + + foreach ($c in $Check) { + # So that if the only check passed in is not yet converted + if ($c -in $notv5) { + $Message = "You are running a check {0} that is not yet converted to v5." -f $c + Write-PSFMessage -Message $Message -Level Warning + } + } } catch { Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_ Return @@ -391,7 +406,13 @@ function Invoke-DbcCheck { } } end { - + foreach ($c in $Check) { + # So that if the only check passed in is not yet converted + if ($c -in $notv5) { + $Message = "You are running a check {0} that is not yet converted to v5." -f $c + Write-PSFMessage -Message $Message -Level Warning + } + } } diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index 895abed2..427385a3 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -18,7 +18,7 @@ $EmailValidationSb = { } Register-PSFConfigValidation -Name validation.EmailValidation -ScriptBlock $EmailValidationSb -$__dbachecksNotv5 = 'ADUser', 'BuiltInAdmin', 'EngineServiceAdmin', 'FullTextServiceAdmin', 'LocalWindowsGroup', 'PublicPermission', 'SqlBrowserServiceAccount', 'TempDbConfiguration','CertificateExpiration', 'DatabaseExists', 'DatabaseGrowthEvent', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'PowerPlan', 'SPN', 'DiskCapacity', 'PingComputer', 'CPUPrioritisation', 'DiskAllocationUnit', 'NonStandardPort', 'ServerProtocol', 'OlaInstalled', 'SystemFull', 'UserFull', 'UserDiff', 'UserLog', 'CommandLog', 'SystemIntegrityCheck', 'UserIntegrityCheck', 'UserIndexOptimize', 'OutputFileCleanup', 'DeleteBackupHistory', 'PurgeJobHistory', 'DomainName', 'OrganizationalUnit', 'ClusterHealth', 'LogShippingPrimary', 'LogShippingSecondary' +$__dbachecksNotv5 = 'ADUser', 'BuiltInAdmin', 'EngineServiceAdmin', 'FullTextServiceAdmin', 'LocalWindowsGroup', 'PublicPermission', 'SqlBrowserServiceAccount', 'TempDbConfiguration','CertificateExpiration', 'DatabaseExists', 'DatabaseGrowthEvent', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'PowerPlan', 'SPN', 'DiskCapacity', 'PingComputer', 'CPUPrioritisation', 'DiskAllocationUnit', 'NonStandardPort', 'ServerProtocol', 'OlaInstalled', 'SystemFull', 'UserFull', 'UserDiff', 'UserLog', 'CommandLog', 'SystemIntegrityCheck', 'UserIntegrityCheck', 'UserIndexOptimize', 'OutputFileCleanup', 'DeleteBackupHistory', 'PurgeJobHistory', 'DomainName', 'OrganizationalUnit', 'ClusterHealth', 'LogShippingPrimary', 'LogShippingSecondary' Set-PSFConfig -Module dbachecks -Name checks.notv5ready -Value @($__dbachecksNotv5) -Initialize -Description "Checks that have not been converted to v5 yet"