if you’ve not heard yet, the people behind the dbatools PowerShell module (including me) have a new toolset for you, dbachecks. dbachecks uses Pester to let you validate your SQL Server estate in a simple way and generate meaningful graphical reports. The official launch of the module is at SQL Bits 2018
Out of the box dbachecks uses test values that we’ve found to be the most appropriate from our years of experience with SQL Server. But these may not be the best values for your particular organisation. For example, we expect to see a Full backup less than 24 hours old for each database, in your case you might only take a Full backup once a week and use differential backups during the week. So we needed a flexible and simple system to let you change the values. dbatools friend Friedrich Weinmann (b | t) has written a great PowerShell module framework called PsFramework which we’ve integrated into dbachecks to handle the configuration of the tests
Out of the box dbachecks will load it’s default config values from the file .\internal\configurations\configuration.ps1 (#! link to GH). To see the current values use
I’ve just picked the top few rows for the screenshot, as of writing (15/02/2018) there are 98 config options available. We’ve tried to make the configuration option names obvious. There are main sections of configuration values group:
- app – Configuration for the module
- domain – Configuration for authentication
- mail – Configuration for sending reports
- policy – The values for the tests
- skip – Controls which tests should be excluded
And each has a useful desription as well to make it easy to find. In the screenshot you’ll notice that I’ve configured the
mail.* options to suit my test environment. So now I can use
Send-DbcMailMessage to email my test results without having to specify all the parameters. To set a configuration parameter you use the
Set-DbcConfig -Name mail.subject -Value "DbcChecks report"
Or perhaps as mentioned at the start of this post, you don’t want a Full backup in the last day, but in the last 7 days. You can easily configure that:
Set-DbcConfig -Name policy.backupfullmaxdays -Value 7
And now your tests will be checking you’re never more than 7 days from a full backup. By default we’re checking that you’ve taken a Differential backup in the last 25 hours, so you’re now good to go!
And don’t worry, you don’t need to reset these every time you run the tests. The PsFramework module persists these non default sessions in the Windows registry at:
So on my system we can see:
Now what happens if you want to distribute these config changes to multiple servers, or share them with colleagues to make sure you’re all singing the same tune. We’d strongly recommend you don’t modify the .\internal\configurations\configuration.ps1 file directly, as that will be replaced whenever you update the module. To make your life easier (which is the entire point of the module) we’ve included Export and import functionality. To export the configuration to an easy to parse JSON file you simply run:
Export-DbcConfig -Path c:\path\of\yourchoice\filename.json
If you omit the path value then by default we will export the results to
$script:localapp\config.json. Now you’ve got a simple JSON file it’s easy to source control (you are using source control aren’t you?) to keep track of changes and make sure they were implemented as expected. If you want to apply that configuration to another install, then it’s simply a case of running the import command:
Import-DbcConfig -Path c:\path\of\yourchoice\filename.json
and you’re done. We support UNC, so again it’s simple to have a central repository to apply the same configuration. And it works well with just fragments of configuration as well, so if all you wanted to control were the email settings you can create a JSON file like this:
"Description": "Number of errors that must be present to generate an email report"
"Description": "Email address the email reports should come from"
"Description": "Store the name of the smtp server to send email reports"
"Value": "DbcChecks report from stuart",
"Description": "Subject line of the email report"
"Description": "Email address to send the report to"
Then you can import just this snippet to set the configuration for those options. Makes it easy to seperate out enterprise level configuration changes from the actual SQL test options. The same technique can be used to ‘force’ the correct backup testing parameters in all cases, while letting other tests be customised as needed.