Skip to content

Commit 6b63331

Browse files
Merge pull request #1015 from dataplat/instancecheckscontinued
so that we stop when we havent converted
2 parents beff153 + c9a4459 commit 6b63331

File tree

5 files changed

+58
-18
lines changed

5 files changed

+58
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- added pester tests to check that changelog is edited.
1111

12+
### Changed
13+
14+
- Fix to Invoke-DbcCheck so that tests that have not been converted to v5 produce warning messages.
15+
1216
## [3.0.1-preview0026] - 2023-08-28
1317

1418
### Added

developing/Oslo Demo.ps1

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,47 @@ $containers = $SQLInstances = $dbachecks1, $dbachecks2, $dbachecks3 = 'dbachecks
77
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
88
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
99
$show = 'All'
10+
11+
$PSDefaultParameterValues = @{
12+
"*:SQlInstance" = $SQLInstances
13+
"*:SqlCredential" = $cred
14+
}
1015
#endregion
1116

1217
#region What do we have?
1318

14-
Get-DbaDatabase -SqlInstance $Sqlinstances -SqlCredential $cred -ExcludeSystem | Select-Object Sqlinstance, DatabaseName, Status
19+
Get-DbaDatabase | Select-Object Sqlinstance, Name, Status
1520

16-
Get-DbaAgentJob -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Name, Enabled
21+
Get-DbaAgentJob | Select-Object Sqlinstance, Name, Enabled
1722
#end region
1823

19-
Get-DbaLastBackup -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table
24+
Get-DbaLastBackup | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table
2025

2126
# lets run a couple of tests
2227

2328
# this one shows that the old existing code will work
2429
# the legacy switch is set to true by default
2530

26-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show
31+
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show
2732

2833
# So lets show the shiny new faster code - legacy switch set to false
2934

30-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
35+
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
3136

3237

3338
# The Authentication check failed but we would like to pass - lets set config
3439
Set-DbcConfig -Name policy.connection.authscheme -Value SQL
3540

3641
# run again
3742

38-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
43+
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
3944

4045
# 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!!
4146
Set-DbcConfig -Name skip.connection.remoting -Value $true
4247

4348
# run again
4449

45-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
50+
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
4651

4752
# 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.
4853

@@ -57,7 +62,7 @@ Invoke-PerfAndValidateCheck -Checks $Checks
5762

5863
# 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
5964

60-
$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru
65+
$CheckResults = Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru
6166

6267
# this is our base results object
6368
$CheckResults
@@ -68,6 +73,7 @@ $SomethingUseful = $CheckResults | Convert-DbcResult
6873

6974
$SomethingUseful
7075
$SomethingUseful | Format-Table
76+
#TODO: fix this Checking Instance Connection on on dbachecks3
7177

7278
$SomethingUseful | Select-Object -First 1
7379

@@ -87,23 +93,25 @@ code ./oslo.json
8793

8894
# or put them into a database table
8995

90-
$CheckResults | Convert-DbcResult -Label 'CoffeeFilter' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose
96+
$CheckResults | Convert-DbcResult -Label 'claudiodidthis' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb
9197

92-
Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT * FROM CheckResults'
98+
Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT COUNT(*) FROM CheckResults'
9399

100+
# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!!
94101
# YOU CANT DO THIS FROM HERE - Open Windows terminal on the host and run
95102

96103
Start-DbcPowerBi -FromDatabase
97104

105+
# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!!
98106
# then use localhost,7401 tempdb and u:sqladmin p:dbatools.IO
99107

100-
# question turn off a container adn talk about hte fails?
108+
# question turn off a container and talk about the fails?
101109

102110

103111
## made some funky results for the Power Bi
104112

105-
$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check Instance, Database -Show $show -legacy $false -PassThru
113+
$CheckResults = Invoke-DbcCheck -Check Instance, Database -Show $show -legacy $false -PassThru
106114

107115
$CheckResults | Convert-DbcResult -Label 'DatabaseInstance' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose
108116

109-
$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check compatibilitylevel -Show $show -legacy $false -PassThru
117+
$CheckResults = Invoke-DbcCheck -Check compatibilitylevel -Show $show -legacy $false -PassThru

developing/Robs-Instance.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ $Checks = 'LoginAuditSuccessful', 'LoginAuditFailed'
2323
Set-DbcConfig -Name skip.security.PublicPermission -Value $false
2424
$Checks = 'PublicRolePermission'
2525
$Checks = 'PUblicPermission'
26+
$Checks = 'Database'
27+
$Checks = 'AgentServiceAccount', 'DbaOperator', 'DatabaseMailProfile', 'AgentMailProfile'
28+
29+
$DatabaseTags = (Get-DbcCheck -Group Database).UniqueTag
30+
31+
$Checks = $DatabaseTags[1..5]
32+
2633

2734
Invoke-PerfAndValidateCheck -Checks $Checks
2835
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail

source/functions/Invoke-DbcCheck.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,26 @@ function Invoke-DbcCheck {
374374
if ($PassThru) {
375375
$configuration.Run.PassThru = $true
376376
}
377-
# So that if the only check passed in is not yet converted - so that we dont get red.
378-
if ($check -in $notv5) {
379-
Write-PSFMessage -Message "You are running a single check that is not yet converted to v5." -Level Warning
377+
# So that if all of the checks passed in are not yet converted so that we stop
378+
379+
# Compare the two arrays
380+
$comparisonResult = Compare-Object -ReferenceObject $check -DifferenceObject $notv5
381+
382+
# If all elements of $check are in $notv5, then $comparisonResult will be either $null or only contain differences where SideIndicator is '=>'
383+
384+
if (($comparisonResult | Where-Object SideIndicator -EQ '<=').Count -eq 0) {
385+
$Message = "The checks that you are running are yet to be converted to v5 unfortunately. We cannot continue. Please use the legacy switch"
386+
Write-PSFMessage -Message $Message -Level Warning
380387
Return
381388
}
389+
390+
foreach ($c in $Check) {
391+
# So that if the only check passed in is not yet converted
392+
if ($c -in $notv5) {
393+
$Message = "You are running a check {0} that is not yet converted to v5." -f $c
394+
Write-PSFMessage -Message $Message -Level Warning
395+
}
396+
}
382397
} catch {
383398
Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_
384399
Return
@@ -391,7 +406,13 @@ function Invoke-DbcCheck {
391406
}
392407
}
393408
end {
394-
409+
foreach ($c in $Check) {
410+
# So that if the only check passed in is not yet converted
411+
if ($c -in $notv5) {
412+
$Message = "You are running a check {0} that is not yet converted to v5." -f $c
413+
Write-PSFMessage -Message $Message -Level Warning
414+
}
415+
}
395416
}
396417

397418

source/internal/configurations/configuration.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $EmailValidationSb = {
1818
}
1919
Register-PSFConfigValidation -Name validation.EmailValidation -ScriptBlock $EmailValidationSb
2020

21-
$__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'
21+
$__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'
2222

2323
Set-PSFConfig -Module dbachecks -Name checks.notv5ready -Value @($__dbachecksNotv5) -Initialize -Description "Checks that have not been converted to v5 yet"
2424

0 commit comments

Comments
 (0)