From 06c96ac3b356c106e18c7bc46d53e868add61c7f Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Mon, 4 Sep 2023 10:33:20 +0000 Subject: [PATCH 1/7] so we dont have to repeat ourselves --- developing/Oslo Demo.ps1 | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) 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 From ef5903c76753faa5840b9b774c9668abd180283c Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Mon, 4 Sep 2023 10:33:53 +0000 Subject: [PATCH 2/7] so that we can check the db tags --- developing/Robs-Instance.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) 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 From bbee39cc5024cd42adb676a7904de2b034c01e2f Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Mon, 4 Sep 2023 10:36:09 +0000 Subject: [PATCH 3/7] so that we know about the unconverted tags --- source/functions/Invoke-DbcCheck.ps1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/functions/Invoke-DbcCheck.ps1 b/source/functions/Invoke-DbcCheck.ps1 index 218e2bc2..4b866d60 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -379,6 +379,13 @@ function Invoke-DbcCheck { Write-PSFMessage -Message "You are running a single check that is not yet converted to v5." -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 +398,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 + } + } } From e366e45b9b2bb3591580936d38657cbdd346f2e9 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Mon, 4 Sep 2023 10:59:37 +0000 Subject: [PATCH 4/7] so that we stop if one or all of the checks are not yet converted --- source/functions/Invoke-DbcCheck.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/source/functions/Invoke-DbcCheck.ps1 b/source/functions/Invoke-DbcCheck.ps1 index 4b866d60..1fd40051 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -374,11 +374,19 @@ 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 {0} 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) { From 05c714f9533bb7083903e9de607634e6b4172916 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Mon, 4 Sep 2023 11:12:05 +0000 Subject: [PATCH 5/7] becuase we list the checks at the end --- source/functions/Invoke-DbcCheck.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/functions/Invoke-DbcCheck.ps1 b/source/functions/Invoke-DbcCheck.ps1 index 1fd40051..2e3ffeb4 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -382,7 +382,7 @@ function Invoke-DbcCheck { # 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 {0} are yet to be converted to v5 unfortunately. We cannot continue. Please use the legacy switch" + $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 } From 00a90c347bebcdb115d88e61df80cf553914a2bd Mon Sep 17 00:00:00 2001 From: jpomfret Date: Tue, 5 Sep 2023 15:43:36 +0000 Subject: [PATCH 6/7] fix typo in config for non v5 --- source/internal/configurations/configuration.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index 96ee4e5b..acff0201 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', 'DatabaseMailEnabled', 'DatabaseMailProfile', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FKCKTrusted', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'PageVerify', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'DatabaseMailEnabled', 'AgentServiceAccount', 'DbaOperator', 'FailsafeOperator', 'DatabaseMailProfile', 'AgentMailProfile', 'FailedJob', 'ValidJobOwner', 'InValidJobOwner', 'AgentAlert', 'JobHistory', 'LongRunningJob', 'LastJobRunTime', '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', 'DatabaseMailEnabled', 'DatabaseMailProfile', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FKCKTrusted', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'PageVerify', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'DatabaseMailEnabled', 'AgentServiceAccount', 'DbaOperator', 'FailsafeOperator', 'DatabaseMailProfile', 'AgentMailProfile', 'FailedJob', 'ValidJobOwner', 'InValidJobOwner', 'AgentAlert', 'JobHistory', 'LongRunningJob', 'LastJobRunTime', '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" From cce1630f8375cb1d7841d3aa570dc92b612fbf21 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Wed, 6 Sep 2023 10:22:09 +0000 Subject: [PATCH 7/7] edit changelog --- CHANGELOG.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4b895bb..60d1a8f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added + +- added pester tests to check that changelog is edited. -- For new features. +### 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 + +- Pester v5 support for agent checks. + + +## [3.0.1-preview0025] - 2023-08-28 + +### Added + +- PageVerify check converted to V5 functionality. ### Changed