· Uwe Janke
Commands / Get-sqmDatabaseSpaceReport

Get-sqmDatabaseSpaceReport

Diagnostics & HealthsqmSQLTool v1.8.2+ · Get🔓 VIEW DATABASE STATE  CSV+HTML Export
Reports how full each database's data and log files are: allocated size vs. actually used space, rolled up per database (data files as a group, log file(s) as a group). This is the classic "database fill level" view - not to be confused with Get-sqmDiskSpaceReport (free space on the underlying Windows volume) or Get-sqmAutoGrowthReport (allocated file size and autogrowth configuration). Databases at or above -WarnThresholdPct / -CriticalThresholdPct are flagged accordingly, both in the returned objects and colour-coded in the HTML report. Pipeline-capable across multiple instances.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEOne or more instances. Pipeline-capable (ValueFromPipeline).
-SqlCredentialPSCredentialOptional, Credentials for the connection.
-Databasestring[]Optional@()Filter: only these databases (wildcards allowed). Default: all accessible.
-ExcludeDatabasestring[]Optional@()Databases to skip (wildcards allowed).
-IncludeSystemDatabasesswitchSwitch$falseAlso include master/model/msdb. tempdb is always included by SQL Server itself but rarely interesting here.
-WarnThresholdPctintOptional80Fill percentage (data or log) at which a database is flagged 'Warning'. Range: 1-100.
-CriticalThresholdPctintOptional90Fill percentage at which a database is flagged 'Critical'. Must be greater than -WarnThresholdPct.
-OutputPathstringOptionalGet-sqmDefaultOutputPath\DatabaseSpaceReportDirectory for the CSV (file-level detail) and HTML (database summary) report.
-ContinueOnErrorswitchSwitch$falseContinue with the next instance on error instead of aborting.
-EnableExceptionswitchSwitch$falseThrow exceptions immediately instead of returning as errors.
-NoOpenswitchSwitch$falseDo not automatically open the HTML report after creation.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES Validate: -CriticalThresholdPct > -WarnThresholdPct throw if not - otherwise every DB would show as both Warning and Critical foreach $instance in $SqlInstance Get-DbaDbSpace (per-file space usage) -ExcludeDatabase adds master/model/msdb/tempdb unless -IncludeSystemDatabases (dbatools' own -IncludeSystemDBs switch is deprecated in 2.8.4 and aborts silently) Per-file detail rows (for CSV) SizeMB / UsedMB / FreeMB / PercentUsed, Status vs. thresholds Aggregate per database: data files vs. log file(s) type_desc = 'LOG' -> log group, everything else -> data group DataPercentUsed / LogPercentUsed = SUM(Used) / SUM(Size) per group Database Status = worse of Data/LogPercentUsed vs. thresholds Critical / Warning / OK Write CSV (file detail) + HTML (database summary, colour-coded) Copy-sqmToCentralPath mirrors both files to the central report path Add instance result to $allInstanceResults, continue loop Return [PSCustomObject[]], one per instance Databases[] (summary) · Files[] (detail) · WarningCount · CriticalCount DONE

Examples

Check database fill level on the local instance
Get-sqmDatabaseSpaceReport -SqlInstance "SQL01"
Tighter critical threshold, list only the databases that aren't OK
Get-sqmDatabaseSpaceReport -SqlInstance "SQL01" -CriticalThresholdPct 95 |
    Select-Object -ExpandProperty Databases | Where-Object Status -ne 'OK'
Check multiple instances via the pipeline, don't abort on the first failure
'SQL01','SQL02' | Get-sqmDatabaseSpaceReport -ContinueOnError