Skip to content

Commit f916963

Browse files
so we cna check login auditing #882
1 parent b3767be commit f916963

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

developing/Robs-Instance.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ $Checks = 'MaxMemory'
1111
$Checks = 'OrphanedFile'
1212
$Checks = 'MemoryDump'
1313
$Checks = 'HideInstance'
14+
$Checks = 'LoginAuditFailed'
15+
$Checks = 'LoginAuditSuccessful'
16+
$Checks = 'LoginAuditSuccessful', 'LoginAuditFailed'
1417

1518
Invoke-PerfAndValidateCheck -Checks $Checks
1619
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail
@@ -19,7 +22,7 @@ $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
1922
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
2023
$show = 'All'
2124

22-
$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
2326
# Run v5 checks
2427
$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose
2528

source/checks/Instancev5.Tests.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,24 @@ Describe "Linked Servers" -Tag LinkedServerConnection, Connectivity, Medium, Ins
200200
}
201201
}
202202

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+
203221
Describe "Instance MaxDop" -Tag MaxDopInstance, MaxDop, Medium, Instance -ForEach ($InstancesToTest | Where-Object { $psitem.Name -notin $psitem.ConfigValues.ExcludeInstanceMaxDop }) {
204222
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.MaxDopInstance' }).Value
205223
Context "Testing Instance MaxDop Value on <_.Name>" {

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ function NewGet-AllInstanceInfo {
400400
}
401401
}
402402

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+
403413
Default { }
404414
}
405415

0 commit comments

Comments
 (0)