Helper functions and tests for SQL Server.
Requires the SqlServer, Pester, and OMSIngestionAPI modules.
For more information refer to the documentation.
First of all import the module.
Import-Module .\src\SQLChecks -ForceAnd then pass a configuration file to Invoke-SqlChecks.
Invoke-SqlChecks -ConfigPath .\examples\simple\localhost.config.jsonYou can also test a single item based on its tag.
Invoke-SqlChecks -ConfigPath .\examples\simple\localhost.config.json -Tag CheckForOversizedIndexesOr loop through a set of configuration files (Invoke-SqlChecks accepts paths on the pipeline, as well as objects from Get-ChildItem).
Get-ChildItem -Filter *.config.json -Path .\examples\simple | Invoke-SqlChecksIt is also possible to pass configurations to Invoke-SqlChecks.
$config = Read-SqlChecksConfig .\examples\simple\localhost.config.json
Invoke-SqlChecks -Config $configYou can find some example configuration files in the examples folder.
Some checks target a database (e.g. checking for oversized indexes). By default these checks will skip:
- Databases that are not ONLINE
- Databases that are secondaries in an availability group
Some checks also exclude system databases by default - for more detail consult the test definitions in the src/SQLChecks/Tests folder.
A config file can specify that databases for a specific availability group should be checked. This is set with the DatabasesToCheck configuration value and the AvailabilityGroup value.
To only run database-specific checks on databases that belong to the AG1 availability group, your config might look like this:
{
"ServerInstance": "localhost",
"DatabasesToCheck": "AGOnly",
"AvailabilityGroup": "AG1"
...
}You can also specify a value of LocalOnly for DatabasesToCheck, which will cause database-specific checks to skip any database that belongs to an availability group.
If you do not specify a value, then every database (except for default exclusions) is checked.
SQLChecks ❤️ PSCore! Tested and working with PSCore 6.2.1rc and SqlServer 21.1.18095preview.
All other dependencies (Pester, OMSIngestionApi) work on Core as of 6.1.