Skip to content
Menu

Is SQL Server Healthy

One health check for every local SQL Server instance: engine and Agent running, databases online, logs not full, no failed Agent jobs, recent FULL backups.

Is SQL Server healthy is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Is SQL Server healthy. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows Server 2016+ with SQL Server 2012+ installed locally; runs as SYSTEM
NeedsPowerShell 5.1; SQL Server on this server; a Windows login with VIEW SERVER STATE and msdb read
Read-onlyReads, changes nothing

What It Does

The script finds every SQL Server instance installed on this server. For each it checks that the SQL Server service is running, and that SQL Agent is running where it exists and is not disabled. A stopped engine is an alert and the other checks for that instance are skipped.

On a running instance it reads every database's state and alerts on any that is not online, reads log space and alerts on logs over MaxLogUsedPercent full (only logs of MinLogSizeMB or more, because a tiny full log simply grows), reads Agent job history for failed runs in the last FailedJobHours, and checks FULL backup age as test-sql-backup-age does.

The answer names the problems per instance. The table has one row per instance with service state and counts or summary values for the checks. A log-shipping secondary or mirror is RESTORING by design, so list it in ExcludeDatabases. On a failover cluster, run it on the active node.

It connects as the account that runs it, normally SYSTEM. If SQL Server refuses the login or a read, the run ends with SQL Server's own message and the account name.

Before You Run It

  • Run it on the SQL Server itself, as SYSTEM from your RMM.
  • Give the run account a login with VIEW SERVER STATE, VIEW ANY DATABASE, read access to msdb and SQLAgentReaderRole.

Type and Risk

  • Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 30 seconds.
  • Example answer: "SQL01: Agent service stopped; database Sales is SUSPECT; Orders log 96% full (8192 MB); 2 failed job(s) in 24 h"
  • Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • MaxLogUsedPercent: Alert when a transaction log is more than this percent full. Whole number, 1 to 99. Default 90.
  • MinLogSizeMB: Only logs at least this big (MB) are checked for fullness. Whole number, 0 to 10000000. Default 100.
  • FailedJobHours: Look for failed Agent jobs this many hours back. Whole number, 1 to 720. Default 24.
  • MaxFullHours: Alert when a database has no FULL backup within this many hours. Whole number, 1 to 8760. Default 26.
  • ExcludeDatabases: Exact database names to leave out of every database check, separated by commas or semicolons. No wildcards. Default empty.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

test-sql-server-health.ps1 · 949 lines · 49.7 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.