Get-sqmWaitStatistics
Performance
sqmSQLTool v1.8.2+ · Get
🔓 VIEW SERVER STATE required
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
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | SQL or Windows credential. |
| -TopN | int | Optional | 25 | Number of top wait types to return. Range: 1–500. |
| -IncludeIdle | switch | Switch | $false | Include known idle waits (SLEEP_*, WAITFOR, XE, HADR background, etc.). Default: excluded. |
| -SnapshotBefore | object[] | Optional | — | Raw snapshot from a prior -SaveSnapshot call. When provided, only the delta (difference) is analysed. |
| -SaveSnapshot | switch | Switch | $false | Return raw $rawWaits immediately without processing — use the result later as -SnapshotBefore. |
| -OutputPath | string | Optional | — | Write a CSV report. File name: WaitStats_Instance_timestamp.csv. Directory created automatically. |
| -EnableException | switch | Switch | $false | Throw on error instead of Write-Error. |
Execution Flow
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"