Skip to content

Commit 93e7275

Browse files
Merge pull request #970 from dataplat/instancecheckscontinued
Instancecheckscontinued
2 parents 6c283e0 + b4e76a5 commit 93e7275

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"extensions": [
1717
"ms-vscode.powershell",
1818
"github.vscode-pull-request-github",
19-
"2gua.rainbow-brackets",
2019
"oderwat.indent-rainbow",
2120
"mhutchie.git-graph",
2221
"usernamehw.errorlens",

developing/Robs-Instance.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ $Checks = 'NetworkLatency'
99
$Checks = 'LinkedServerConnection'
1010
$Checks = 'MaxMemory'
1111
$Checks = 'OrphanedFile'
12+
$Checks = 'MemoryDump'
13+
$Checks = 'HideInstance'
14+
$Checks = 'LoginAuditFailed'
15+
$Checks = 'LoginAuditSuccessful'
16+
$Checks = 'LoginAuditSuccessful', 'LoginAuditFailed'
1217

1318
Invoke-PerfAndValidateCheck -Checks $Checks
1419
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail
@@ -17,7 +22,7 @@ $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
1722
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
1823
$show = 'All'
1924

20-
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
25+
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru -verbose
2126
# Run v5 checks
2227
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
2328

@@ -44,4 +49,4 @@ $traci = Trace-Script -ScriptBlock {
4449
$v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru
4550
}
4651

47-
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check failsafeoperator -legacy $false -Show $show -verbose
52+
Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check failsafeoperator -legacy $false -Show $show -verbose

source/checks/Instancev5.Tests.ps1

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $Inst
140140
}
141141
}
142142

143+
Describe "Hide Instance" -Tag HideInstance, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
144+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.hideinstance' }).Value
145+
Context "Checking the Hide an Instance of SQL Server Database Engine property on <_.Name>" {
146+
It "The Hide an Instance of SQL Server Database Engine property on SQL Server instance <_.Name>" -Skip:$skip {
147+
# We don't make this -BeTrue because the possible results are $true/$false/'Could not connect'
148+
$psitem.HideInstance.Result | Should -Be $true -Because "We expected the hide instance property to be set to $true"
149+
}
150+
}
151+
}
152+
143153
Describe "Instance Connection" -Tag InstanceConnection, Connectivity, High, Instance -ForEach $InstancesToTest {
144154
BeforeAll {
145155
$skipall = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection' }).Value
@@ -190,6 +200,33 @@ Describe "Linked Servers" -Tag LinkedServerConnection, Connectivity, Medium, Ins
190200
}
191201
}
192202

203+
Describe "Failed Login Auditing" -Tag LoginAuditFailed, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
204+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.loginauditlevelfailed' }).Value
205+
Context "Testing if failed login auditing is in place on <_.Name>" {
206+
It "The failed login auditing should be set on <_.Name>" -Skip:$skip {
207+
$psitem.Settings.AuditLevel | Should -BeIn @("Failure", "All") -Because "We expected the audit level to be set to capture failed logins"
208+
}
209+
}
210+
}
211+
212+
Describe "Successful Login Auditing" -Tag LoginAuditSuccessful, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
213+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.loginauditlevelsuccessful' }).Value
214+
Context "Testing if successful and failed login auditing is in place on <_.Name>" {
215+
It "The successful and failed auditing should be set on <_.Name>" -Skip:$skip {
216+
$psitem.Settings.AuditLevel | Should -Be "All" -Because "We expected the audit level to be set to capture all logins (successful and failed)"
217+
}
218+
}
219+
}
220+
221+
Describe "Login Check Policy" -Tag LoginCheckPolicy, Security, CIS, Medium, Instance -ForEach $InstancesToTest {
222+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.LoginCheckPolicy' }).Value
223+
Context "Testing if the CHECK_POLICY is enabled on all logins on $psitem" {
224+
It "All logins should have the CHECK_POLICY option set to ON on $psitem" -Skip:$skip {
225+
($psitem.logins | Where-Object { $_.LoginType -eq 'SqlLogin' -and $_.PasswordPolicyEnforced -eq $false -and $_.IsDisabled -eq $false }).Count | Should -Be 0 -Because "We expected the CHECK_POLICY for the all logins to be enabled"
226+
}
227+
}
228+
}
229+
193230
Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) {
194231
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.MaxDopInstance' }).Value
195232
Context "Testing Instance MaxDop Value on <_.Name>" {
@@ -213,11 +250,11 @@ Describe "Max Memory" -Tag MaxMemory, High, Instance -ForEach $InstancesToTest {
213250
}
214251
}
215252

216-
Describe "SQL Memory Dumps" -Tags MemoryDump, Medium, Instance -ForEach $InstancesToTest {
253+
Describe "SQL Memory Dumps" -Tag MemoryDump, Medium, Instance -ForEach $InstancesToTest {
217254
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.memorydump' }).Value
218255
Context "Testing SQL Memory Dumps on <_.Name>" {
219256
It "There should be less than <_.MemoryDump.MaxDumps> since <_.MemoryDump.DumpDateCheckFrom> on <_.Name>" -Skip:$skip {
220-
$Psitem.MemoryDump.Result | Should -BeTrue -Because "We expected less than $($Psitem.MemoryDump.MaxDumps) dumps since $(PsItem.MemoryDump.DumpDateCheckFrom)but found $($Psitem.MemoryDump.DumpCount) . Memory dumps often suggest issues with the SQL Server instance"
257+
$Psitem.MemoryDump.Result | Should -BeTrue -Because "We expected less than $($Psitem.MemoryDump.MaxDumps) dumps since $($PsItem.MemoryDump.DumpDateCheckFrom)but found $($Psitem.MemoryDump.DumpCount) . Memory dumps often suggest issues with the SQL Server instance"
221258
}
222259
}
223260
}

source/functions/Invoke-DbcCheck.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,13 @@ function Invoke-DbcCheck {
288288
process {
289289
if ($legacy) {
290290
try {
291+
Write-PSFMessage 'Running in legacy mode, we need Version 4'
291292
if (Get-Module Pester | Where-Object { $_.Version -gt '5.0.0' }) {
293+
Write-PSFMessage 'Remove Version 5' -Level Verbose
292294
Remove-Module Pester -ErrorAction SilentlyContinue
293-
Write-PSFMessage 'Running in legacy mode, we need to import Version 4' -Level Verbose
294-
Import-Module Pester -RequiredVersion 4.10.1 -Global
295295
}
296+
Write-PSFMessage 'import Version 4' -Level Verbose
297+
Import-Module Pester -RequiredVersion 4.10.1 -Global
296298
} catch {
297299
Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_
298300
Return

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,34 @@ function NewGet-AllInstanceInfo {
388388
}
389389
}
390390

391+
'HideInstance' {
392+
try {
393+
$HideInstance = [pscustomobject] @{
394+
Result = (Get-DbaHideInstance -SqlInstance $InstanceSMO).HideInstance
395+
}
396+
} catch {
397+
$HideInstance = [pscustomobject] @{
398+
Result = 'We Could not Connect to $Instance'
399+
}
400+
}
401+
}
402+
403+
'LoginAuditFailed' {
404+
$SettingsInitFields.Add("AuditLevel") | Out-Null # so we can check auditlevel
405+
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $SettingsInitFields)
406+
}
407+
408+
'LoginAuditSuccessful' {
409+
$SettingsInitFields.Add("AuditLevel") | Out-Null # so we can check auditlevel
410+
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $SettingsInitFields)
411+
}
412+
413+
'LoginCheckPolicy' {
414+
$LoginInitFields.Add("IsDisabled") | Out-Null # so we can check login check policy
415+
$LoginInitFields.Add("PasswordPolicyEnforced") | Out-Null # so we can check login check policy
416+
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $LoginInitFields)
417+
}
418+
391419
Default { }
392420
}
393421

@@ -487,6 +515,7 @@ function NewGet-AllInstanceInfo {
487515
renamerequired = $ServerNameMatchrenamerequired
488516
}
489517
MemoryDump = $Dump
518+
HideInstance = $HideInstance
490519
# TempDbConfig = [PSCustomObject]@{
491520
# TF118EnabledCurrent = $tempDBTest[0].CurrentSetting
492521
# TF118EnabledRecommended = $tempDBTest[0].Recommended

0 commit comments

Comments
 (0)