A SQL health check is an automated PowerShell procedure that connects to a SQL instance, verifies that databases use the SIMPLE recovery model, and emails a notification when a database has an undesired configuration. section 4.0
Build the automation around four operational concerns:
- Retrieve SQL connection data from a secret vault rather than embedding credentials in the script. section 4.0 section 4.4.1
- Run a dbatools diagnostic query against the selected SQL instance and inspect its Results output. section 4.4.1
- Filter database properties for recovery models that are not SIMPLE. section 4.0
- Send an email through SendGrid when the check finds a failure. section 4.0 section 4.4.1
Validate the dependencies before combining them
Retrieve SQL credentials and the server name with Get-Secret, then call Invoke-DbaDiagnosticQuery with the Database Properties query. Separately retrieve the SendGrid address and API key, send a test message with Send-EmailMessage, and proceed only after both tests work. section 4.4.1
