From c9ced52ed4df655b4a4bce31534ee58c59adc846 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Fri, 27 May 2022 19:50:34 +0100 Subject: [PATCH] autoclose - #884 --- checks/Databasev5.Tests.ps1 | 9 +++++++++ internal/configurations/configuration.ps1 | 1 + internal/functions/Get-AllDatabaseInfo.ps1 | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index ed49012f..b6de8527 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -110,4 +110,13 @@ Describe "Auto Close" -Tag AutoClose, High, Database -ForEach $InstancesToTest { $psitem.AutoClose | Should -Be $psitem.ConfigValues.autoclose -Because "Because!" } } +} + +Describe "Auto Shrink" -Tag AutoShrink, High, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.autoshrink + Context "Testing Auto Shrink on <_.Name>" { + It "Database <_.Name> should have Auto Shrink set to <_.ConfigValues.autoshrink> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autoshrinkexclude -notcontains $PsItem.Name } } { + $psitem.AutoShrink | Should -Be $psitem.ConfigValues.autoshrink -Because "Shrinking databases causes fragmentation and performance issues" + } + } } \ No newline at end of file diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index 3ce612d2..9c646ac5 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -231,6 +231,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali # exclude databases Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value @('master', 'msdb', 'tempdb') -Initialize -Description "Databases to exclude from asymmetric key size checks" Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks" +Set-PSFConfig -Module dbachecks -Name policy.autoshrink.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks" diff --git a/internal/functions/Get-AllDatabaseInfo.ps1 b/internal/functions/Get-AllDatabaseInfo.ps1 index 7508da48..8f5e9e0b 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -60,6 +60,12 @@ function Get-AllDatabaseInfo { $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocloseexclude' -Value (Get-DbcConfigValue policy.autoclose.excludedb) } + 'AutoShrink' { + $autoshrink = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrinkexclude' -Value (Get-DbcConfigValue policy.autoshrinke.excludedb) + } + 'ValidDatabaseOwner' { $owner = $true $ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name) @@ -103,6 +109,7 @@ function Get-AllDatabaseInfo { AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count } #AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key AutoClose = if ($autoclose) { $psitem.AutoClose} + AutoShrink = if ($autoshrink) { $psitem.AutoShrink} } } }