Get-sqmBlockingReport
Blocking & Locking
sqmSQLTool v1.8.2+ · Get
🔓 VIEW SERVER STATE required
sys.dm_exec_requests, sys.dm_exec_sessions, and sys.dm_exec_sql_text. Resolves the exact SQL statement for both the blocked and blocking session via statement_start/end_offset. Returns structured objects with BlockingChains, HeadBlockers, BlockedSessions, and a HasBlocking flag — suitable for Agent Job monitoring or pipeline-based alerting. Optionally writes a CSV snapshot per run.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | SQL or Windows credential for the connection. |
| -MinWaitSeconds | int | Optional | 0 | Only report sessions with a wait time ≥ this value. Applied in SQL as wait_time / 1000.0 ≥ N. |
| -OutputPath | string | Optional | — | When provided AND blocking exists, writes a CSV snapshot. Directory is created automatically if missing. |
| -EnableException | switch | Switch | $false | Throw on error instead of Write-Error. |
Execution Flow
Return Object
| Property | Type | Description |
|---|---|---|
| .HasBlocking | bool | $true if any blocking was found. |
| .BlockedCount | int | Total number of blocked sessions. |
| .BlockingChains | List | One entry per true head blocker: HeadBlockerSpid, HeadLogin, HeadStatement, HeadStartTime, BlockedSpids[], BlockedCount, MaxWaitSeconds. |
| .HeadBlockers | int[] | SPIDs that are blocking others but are not themselves blocked. |
| .BlockedSessions | List | All blocked session records with full detail (login, host, statement, wait info, CPU, logical reads, ChainDepth). |
Examples
Check for blocking on the local instance
Get-sqmBlockingReport
Only report sessions waiting longer than 30 seconds
Get-sqmBlockingReport -SqlInstance "SQL01" -MinWaitSeconds 30
Use HasBlocking flag for conditional alerting
if ((Get-sqmBlockingReport -SqlInstance "SQL01").HasBlocking) {
Write-Warning "Active blocking detected!"
}Agent Job: write CSV snapshot whenever blocking occurs
Get-sqmBlockingReport -SqlInstance "SQL01" -OutputPath "C:\System\WinSrvLog\MSSQL\Blocking"