Commands / Get-sqmDatabaseHealth
Get-sqmDatabaseHealth
Database Health sqmSQLTool v1.8.2+ · Get ✓ -WhatIf supported
Aggregated health report for all databases on an instance. Checks CHECKDB age, last backup times (Full/Diff/Log), VLF count, AutoGrowth events (from Default Trace), database size, and database status. Saves results as TXT and CSV to the output path and returns a structured object.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEPipeline-capable. Multiple instances supported.
-SqlCredentialPSCredentialOptional
-MaxCheckDbAgeDaysintOptional14CHECKDB older than this → Warning.
-MaxVlfCountintOptional200VLF count above this → Warning.
-HistoryDaysintOptional30AutoGrowth evaluation window (Default Trace).
-ExcludeDatabasestring[]OptionalWildcards allowed. tempdb always excluded.
-IncludeSystemDatabasesswitchSwitch$falseInclude master/model/msdb. tempdb always excluded.
-OutputPathstringOptionalC:\System\WinSrvLog\MSSQLCreated automatically if it does not exist.
-ContinueOnErrorswitchSwitch$falseContinue to next instance on error instead of throwing.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES -SqlInstance provided? NO → Default: $env:COMPUTERNAME Get-DbaDatabase (excl. tempdb always) -IncludeSystemDatabases: NO → also excl. master/model/msdb Per database — 4 parallel queries CHECKDB age (DATABASEPROPERTYEX) Last Backup (msdb.backupset) VLF count (sys.dm_db_log_info*) AutoGrowth events (Default Trace) * SQL < 2016: VLF = "Unknown" (sys.dm_db_log_info n/a) Determine status per database Critical: DB status ≠ Normal (Suspect, Restoring, …) Warning: CHECKDB age > MaxCheckDbAgeDays OR VLF > MaxVlfCount OK: all checks passed OutputPath exists? NO New-Item -Force create directory YES Write TXT report + CSV file DatabaseHealth_InstanceName_YYYY-MM-DD.txt + .csv → OutputPath TXT: summary table sorted by status (Critical first) · CSV: all detail columns Return [PSCustomObject] SqlInstance · Timestamp · DetailRows · TxtFile · CsvFile Status: OK / Warning / Critical (highest across all DBs) Instance error? -ContinueOnError: continue to next instance · else throw DONE (pipeline: next instance)

Examples

Health check — local instance, default thresholds
Get-sqmDatabaseHealth
Multiple instances including system databases
Get-sqmDatabaseHealth -SqlInstance "SQL01","SQL02" -IncludeSystemDatabases -OutputPath "D:\Reports"
Stricter CHECKDB threshold, longer AutoGrowth window
Get-sqmDatabaseHealth -SqlInstance "SQL01" -MaxCheckDbAgeDays 7 -MaxVlfCount 100 -HistoryDays 60
Pipeline — check all instances from OU
Get-sqmServersFromOU -OUPath "OU=SQL,DC=corp,DC=local" | Get-sqmDatabaseHealth -ContinueOnError