Commands / Get-sqmWaitStatistics
Get-sqmWaitStatistics
Performance sqmSQLTool v1.8.2+ · Get 🔓 VIEW SERVER STATE required
Reads cumulative wait statistics from sys.dm_os_wait_stats, filters known idle wait types, and returns the Top-N waits with category classification and built-in action recommendations (25+ known wait types covering I/O, Locking, Parallelism, Memory, CPU, Latch, Network). Supports delta snapshot comparison: capture a baseline with -SaveSnapshot, run a workload, then pass the baseline as -SnapshotBefore to measure only the interval difference. Results can be exported as CSV.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestringOptional$env:COMPUTERNAMETarget SQL Server instance.
-SqlCredentialPSCredentialOptionalSQL or Windows credential.
-TopNintOptional25Number of top wait types to return. Range: 1–500.
-IncludeIdleswitchSwitch$falseInclude known idle waits (SLEEP_*, WAITFOR, XE, HADR background, etc.). Default: excluded.
-SnapshotBeforeobject[]OptionalRaw snapshot from a prior -SaveSnapshot call. When provided, only the delta (difference) is analysed.
-SaveSnapshotswitchSwitch$falseReturn raw $rawWaits immediately without processing — use the result later as -SnapshotBefore.
-OutputPathstringOptionalWrite a CSV report. File name: WaitStats_Instance_timestamp.csv. Directory created automatically.
-EnableExceptionswitchSwitch$falseThrow on error instead of Write-Error.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES -SqlInstance provided? NO → Default: $env:COMPUTERNAME SELECT from sys.dm_os_wait_stats (master) waiting_tasks_count > 0 · avg_wait_ms computed inline · ORDER BY wait_time_ms DESC -SaveSnapshot set? YES return $rawWaits immediately SaveSnapshot mode — early exit NO Data preparation -SnapshotBefore provided → subtract previous values per wait_type (delta) · else: use raw data -IncludeIdle: NO → remove ~30 known idle wait types (SLEEP_*, XE, HADR background, …) Sort · Top-N · Enrich Sort by wait_time_ms DESC · Select -First TopN Add Category + Recommendation (built-in table, 25+ types) · WaitTimePct = ms / total * 100 -OutputPath provided? YES Export-Csv WaitStats_Instance_timestamp.csv NO Return [PSCustomObject[]] — Top-N entries WaitType · Category · WaitTimeSec · WaitTimePct · WaitingTasksCount · AvgWaitMs MaxWaitMs · SignalWaitMs · ResourceWaitMs · IsDelta · Recommendation Error handling -EnableException: throw · else: Write-Error DONE

Examples

Top 25 waits on the local instance (idle waits excluded)
Get-sqmWaitStatistics
Top 20 waits on a named instance
Get-sqmWaitStatistics -SqlInstance "SQL01" -TopN 20
Delta snapshot — measure waits during a specific workload
# Step 1: capture baseline
$before = Get-sqmWaitStatistics -SqlInstance "SQL01" -SaveSnapshot

# Step 2: run workload …

# Step 3: compare — returns only the delta
Get-sqmWaitStatistics -SqlInstance "SQL01" -SnapshotBefore $before
Export to CSV, include idle waits
Get-sqmWaitStatistics -SqlInstance "SQL01" -IncludeIdle -OutputPath "C:\System\WinSrvLog\MSSQL"