From 7ec8934a142e16309ec9495d662b4bab597add85 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 26 Aug 2023 15:21:24 +0000 Subject: [PATCH 1/5] fixing stuff Add Pester V5 Instance Level Checks #882 --- containers/JessAndBeard.psm1 | 41 ++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/containers/JessAndBeard.psm1 b/containers/JessAndBeard.psm1 index a37c5631..92167ee4 100644 --- a/containers/JessAndBeard.psm1 +++ b/containers/JessAndBeard.psm1 @@ -2365,6 +2365,13 @@ The Tags are the same" PassedChange = +2 # + or - the number of tests passed for v5 FailedChange = -2 # + or - the number of tests failed for v5 SkippedChange = 0 # + or - the number of tests skipped for v5 + }, + @{ + Name = 'SqlEngineServiceAccount' + RunChange = -3 # + or - the number of tests run for v5 + PassedChange = 0 # + or - the number of tests passed for v5 + FailedChange = 0 # + or - the number of tests failed for v5 + SkippedChange = -3 # + or - the number of tests skipped for v5 } ) $runchange = 0 @@ -2414,6 +2421,7 @@ The Total Tests Run are the same {0} {1} #total passed checks If ($v5Passed -ne $v4code.PassedCount) { + $Message = " Uh-Oh - The total tests Passed between v4 and v5 are not the same somehow. For v4 We Passed @@ -2422,11 +2430,16 @@ and For v5 we Passed {1} tests {2} + +" -f $v4code.PassedCount, $v5Passed, $messageAppend + if($MessageAppend){ + $Message += " v4 TestNames -{3} +{0} v5 TestNames -{4} -" -f $v4code.PassedCount, $v5Passed, $messageAppend, ($v4code.TestResult.Where{$_.Result -eq 'Passed'}.Name |Out-String),($v5code.Passed.ExpandedName |Out-String) +{1} + " -f ($v4code.TestResult.Where{$_.Result -eq 'Passed'}.Name |Out-String),($v5code.Passed.ExpandedName |Out-String) + } Write-PSFMessage -Message $Message -Level Warning } else { $message = " @@ -2443,11 +2456,16 @@ For v4 We Failed and For v5 we Failed {1} tests + +" -f $v4code.FailedCount, $v5Failed, $messageAppend + if($MessageAppend){ + $Message += " v4 TestNames -{2} +{0} v5 TestNames -{3} -" -f $v4code.FailedCount, $v5failed,($v4code.TestResult.Where{$_.Result -eq 'Failed'}.Name |Out-String),($v5code.Failed.ExpandedName |Out-String) +{1} + " -f ($v4code.TestResult.Where{$_.Result -eq 'Failed'}.Name |Out-String),($v5code.Failed.ExpandedName |Out-String) + } Write-PSFMessage -Message $Message -Level Warning } else { $message = " @@ -2464,11 +2482,16 @@ For v4 We Skipped and For v5 we Skipped {1} + +" -f $v4code.SkippedCount, $v5Skipped, $messageAppend + if($MessageAppend){ + $Message += " v4 TestNames -{3} +{0} v5 TestNames -{4} -{2}" -f $v4code.SkippedCount, $v5skipped, $messageAppend,($v4code.TestResult.Where{$_.Result -eq 'Skipped'}.Name |Out-String),($v5code.Skipped.ExpandedName |Out-String) +{1} + " -f ($v4code.TestResult.Where{$_.Result -eq 'Skipped'}.Name |Out-String),($v5code.Skipped.ExpandedName |Out-String) + } Write-PSFMessage -Message $Message -Level Warning } else { $message = " From 03f9d8da5c930805e9578e46e4a332e1b7dab45a Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 26 Aug 2023 15:23:06 +0000 Subject: [PATCH 2/5] not tags Add Pester V5 Instance Level Checks #882 --- source/checks/Instancev5.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/checks/Instancev5.Tests.ps1 b/source/checks/Instancev5.Tests.ps1 index fb298938..e3d304d3 100644 --- a/source/checks/Instancev5.Tests.ps1 +++ b/source/checks/Instancev5.Tests.ps1 @@ -426,7 +426,7 @@ Describe "SQL and Windows names match" -Tag ServerNameMatch, Medium, Instance -F } } -Describe "SQL Engine Service" -Tags SqlEngineServiceAccount, ServiceAccount, High, Instance -ForEach $InstancesToTest { +Describe "SQL Engine Service" -Tag SqlEngineServiceAccount, ServiceAccount, High, Instance -ForEach $InstancesToTest { $skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.sqlengineserviceaccount' }).Value Context "Testing SQL Engine Service on <_.Name>" -Skip:$skip { It "SQL Engine service account should be <_.State> on <_.InstanceName>" -ForEach $PsItem.SqlEngineServiceAccount { From 3772dec82cfb11f94df594b8679db8e1a2e2e2c9 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 26 Aug 2023 15:23:43 +0000 Subject: [PATCH 3/5] so we have list of not yet converted checks Add Pester V5 Instance Level Checks #882 --- source/internal/configurations/configuration.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index 3d0baf35..96ee4e5b 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -18,6 +18,10 @@ $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' + +Set-PSFConfig -Module dbachecks -Name checks.notv5ready -Value @($__dbachecksNotv5) -Initialize -Description "Checks that have not been converted to v5 yet" + # some configs to help with autocompletes and other module level stuff #apps From 0d70a3cd1b84c427816fa76e036267da98b05bb0 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 26 Aug 2023 15:24:15 +0000 Subject: [PATCH 4/5] so we exclude the not converted cheks and stop if only one Add Pester V5 Instance Level Checks #882 --- source/functions/Invoke-DbcCheck.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/functions/Invoke-DbcCheck.ps1 b/source/functions/Invoke-DbcCheck.ps1 index a79d8a52..ca1aeeb1 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -367,10 +367,18 @@ function Invoke-DbcCheck { $configuration = New-PesterConfiguration $configuration.Output.Verbosity = $NewShow $configuration.Filter.Tag = $check + 'FailedConnections' - $configuration.Filter.ExcludeTag = $ExcludeCheck + # Exclude the excluded checks and the not converted checks + $notv5 = (Get-PSFConfigValue -FullName 'dbachecks.checks.notv5ready') + $configuration.Filter.ExcludeTag = $ExcludeCheck + $notv5 + 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 + Return + } } catch { Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_ Return From fcab7db66237fafcc2571ede61d4c55c90b7cf50 Mon Sep 17 00:00:00 2001 From: Rob Sewell Date: Sat, 26 Aug 2023 16:35:10 +0100 Subject: [PATCH 5/5] so that we dont have the additional output for v5 Add Pester V5 Instance Level Checks #882 --- 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 ca1aeeb1..218e2bc2 100644 --- a/source/functions/Invoke-DbcCheck.ps1 +++ b/source/functions/Invoke-DbcCheck.ps1 @@ -386,7 +386,7 @@ function Invoke-DbcCheck { $null = $PSBoundParameters.Remove('legacy') $null = $PSBoundParameters.Remove('Show') $null = $PSBoundParameters.Remove('PassThru') - Write-PSFMessage -Message ($PSBoundParameters | Out-String) -Level Significant + Write-PSFMessage -Message ($PSBoundParameters | Out-String) -Level Verbose Invoke-DbcCheckv5 @PSBoundParameters -configuration $configuration } }