Skip to content

Commit 63dbcaa

Browse files
committed
new check LIVE AND IN PERSON!
1 parent 782a74d commit 63dbcaa

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

source/checks/Databasev5.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,13 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo
232232
}
233233
}
234234
}
235+
236+
Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest {
237+
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value
238+
239+
Context "Testing Recovery Model" {
240+
It "Database <_.Name> should be set to <_.ConfigValues.recoverymodeltype> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.recoverymodelexclude -notcontains $psitem.Name } } {
241+
$psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model."
242+
}
243+
}
244+
}

source/internal/configurations/configuration.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchro
324324
Set-PSFConfig -Module dbachecks -Name skip.database.trustworthy -Validation bool -Value $false -Initialize -Description "Skip the trustworthy database test"
325325
Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Value $false -Initialize -Description "Skip the database status test"
326326
Set-PSFConfig -Module dbachecks -Name skip.database.compatibilitylevel -Validation bool -Value $false -Initialize -Description "Skip the database compatibility test"
327+
Set-PSFConfig -Module dbachecks -Name skip.database.recoverymodel -Validation bool -Value $false -Initialize -Description "Skip the database recovery model test"
327328

328329

329330
Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"

source/internal/functions/Get-AllDatabaseInfo.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ function Get-AllDatabaseInfo {
139139
$guestUserConnect = $true
140140
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value
141141
}
142+
'RecoveryModel' {
143+
$recoverymodel = $true
144+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodeltype' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.type').Value
145+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodelexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.excludedb').Value
146+
}
142147
Default { }
143148
}
144149

@@ -174,6 +179,7 @@ function Get-AllDatabaseInfo {
174179
CompatibilityLevel = @(if ($compatibilitylevel) { $psitem.CompatibilityLevel })
175180
ServerLevel = @(if ($compatibilitylevel) { [Enum]::GetNames('Microsoft.SqlServer.Management.Smo.CompatibilityLevel').Where{ $psitem -match $Instance.VersionMajor } })
176181
GuestUserConnect = @(if ($guestUserConnect) { if ($psitem.EnumDatabasePermissions('guest') | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect }) { $true } } )
182+
RecoveryModel = @(if ($recoverymodel) { $psitem.RecoveryModel })
177183
}
178184
}
179185
}

0 commit comments

Comments
 (0)