Get-sqmWhoIsActive
Session ManagementsqmSQLTool v1.9.127+ · Get🔓 VIEW SERVER STATE
sp_whoisactive but without installing anything on the target instance: everything is built from sys.dm_exec_sessions, sys.dm_exec_requests, sys.dm_exec_sql_text and sys.dm_db_session_space_usage, all available on any SQL Server 2012+ instance. One row per relevant session: SPID, login/host/program, database, status, blocking SPID, wait info, elapsed time, CPU/reads/writes, tempdb allocation and the running (or last) SQL statement. With -RepeatIntervalSeconds the query re-runs on an interval, like sp_whoisactive's @sleep_time but driven from the client side, until -RepeatCount iterations or -DurationMinutes elapse, or you press Ctrl+C. Every iteration is collected, and one CSV (full detail) plus one HTML report (last snapshot) is written at the end, including when the loop is cancelled early. For a live-refreshing grid instead of console output, use Show-sqmWhoIsActiveMonitor.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | , | SQL or Windows credential. Without it: Windows authentication. |
| -ShowSleepingSpids | int (0,1,2) | Optional | 1 | Mirrors sp_whoisactive's @show_sleeping_spids: 0 = only sessions with an active request, 1 = plus idle sessions with an open transaction, 2 = all user sessions. |
| -MinElapsedSeconds | int | Optional | 0 | Only report sessions whose current request (or last batch) has been running/idle for at least this many seconds. |
| -RepeatIntervalSeconds | int | Optional | 0 | Seconds between snapshots. 0 = run once, no repeat. |
| -RepeatCount | int | Optional | 0 | Number of snapshots when repeating. 0 = until -DurationMinutes elapses or Ctrl+C. Ignored when the interval is 0. |
| -DurationMinutes | int | Optional | 0 | Stop repeating after this many minutes. 0 = unlimited. |
| -OutputPath | string | Optional | Get-sqmDefaultOutputPath\WhoIsActive | Directory for the CSV/HTML report. |
| -NoConsoleOutput | switch | Switch | $false | Suppress the live table printed after every snapshot. For unattended/Agent job runs where only the report matters. |
| -NoOpen | switch | Switch | $false | Do not automatically open the generated report. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately instead of returning as errors. |
Execution Flow
Examples
Single snapshot, like running sp_whoisactive once
Get-sqmWhoIsActive -SqlInstance "SQL01"
Live monitor: refresh every 5 seconds until Ctrl+C
Get-sqmWhoIsActive -SqlInstance "SQL01" -RepeatIntervalSeconds 5
30 snapshots (5 minutes), only sessions busy for 5+ seconds
Get-sqmWhoIsActive -SqlInstance "SQL01" -RepeatIntervalSeconds 10 -RepeatCount 30 -MinElapsedSeconds 5
Unattended capture for an Agent job: one hour, no console output
Get-sqmWhoIsActive -SqlInstance "SQL01" -RepeatIntervalSeconds 30 -DurationMinutes 60 -NoConsoleOutput
Only the blocked sessions of the current snapshot
$w = Get-sqmWhoIsActive -SqlInstance "SQL01"
$w.LastSnapshot | Where-Object { $_.BlockingSpid -gt 0 }