Invoke-sqmExtendedEvents
PerformancesqmSQLTool v1.8.2+ · Performance Diagnosticsdbatools required • ShouldProcess Medium • 5 Templates
Execution Flow
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | Credentials for the connection. |
| -SessionName | string | Optional | sqmPerformance | Name of the XEvent session. |
| -Template | string | Optional | AllInOne | SlowQueries | Blocking | Waits | Deadlocks | AllInOne. |
| -SlowQueryThresholdMs | int | Optional | 1000 | Min duration (ms) for slow query capture. |
| -WaitTypes | string | Optional | LCK_M_X,LCK_M_S,... | Comma-separated wait types for Waits template. |
| -TargetType | string | Optional | RingBuffer | RingBuffer or File target. |
| -TargetFilePath | string | Optional | OutputPath\XEvents | Directory for XEL files (File target only). |
| -MaxFileSizeMB | int | Optional | 100 | Max XEL file size in MB. |
| -RingBufferMaxMB | int | Optional | 50 | Max ring buffer size in MB. |
| -MaxEventsRead | int | Optional | 10000 | Maximum events read per call. |
| -LookbackMinutes | int | Optional | 60 | Time window for diagnostic aggregation. |
| -TopN | int | Optional | 25 | Top entries in diagnostic tables. |
| -Create | switch | Switch | — | Create session (drops existing first). |
| -Start | switch | Switch | — | Start existing session. |
| -Stop | switch | Switch | — | Stop running session. |
| -Read | switch | Switch | — | Read events from ring buffer or XEL file. |
| -Diagnose | switch | Switch | — | Aggregate events and detect patterns. |
| -Drop | switch | Switch | — | Remove session including XEL files. |
| -EnableException | switch | Switch | $false | Re-throw exceptions immediately. |
Examples
Create AllInOne session and start — default Read+Diagnose on next call
Invoke-sqmExtendedEvents -SqlInstance "SQL01" -Create -Start
Capture slow queries > 2s to XEL file
Invoke-sqmExtendedEvents -SqlInstance "SQL01" -Template SlowQueries -SlowQueryThresholdMs 2000 -TargetType File -Create -Start
Read running session and diagnose (default behavior)
Invoke-sqmExtendedEvents -SqlInstance "SQL01"
Stop and remove session
Invoke-sqmExtendedEvents -SqlInstance "SQL01" -Stop -Drop