dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Start-DbaXESmartTarget

XESmartTarget offers the ability to set up complex actions in response to Extended Events captured in sessions, without writing a single line of code.

See more at Github.

Screenshots

dbatools-New-DbaXESmartReplay

Examples

Executes a T-SQL command against dbadb on sql2017 whenever a deadlock event is recorded.

$response = New-DbaXESmartQueryExec -SqlInstance sql2017 -Database dbadb -Query “update table set whatever = 1”
Start-DbaXESmartTarget -SqlInstance sql2017 -Session deadlock_tracker -Responder $response

Executes a T-SQL command against dbadb on sql2017 and sends an email whenever a querytracker event is recorded.

$response = New-DbaXESmartQueryExec -SqlInstance sql2017 -Database dbadb -Query “update table set whatever = 1”
$params = @{
SmtpServer = “smtp.ad.local”
To = “[email protected]
Sender = “[email protected]
Subject = “Query executed”
Body = “Query executed at {collection_time}”
Attachment = “batch_text”
AttachmentFileName = “query.sql”
}
$emailresponse = New-DbaXESmartEmail @params
Start-DbaXESmartTarget -SqlInstance sql2017 -Session querytracker -Responder $response, $emailresponse

Writes Extended Events to the deadlocktracker table in dbadb on sql2017.

$columns = “cpu_time”, “duration”, “physical_reads”, “logical_reads”, “writes”, “row_count”, “batch_text”
$response = New-DbaXESmartTableWriter -SqlInstance sql2017 -Database dbadb -Table deadlocktracker -OutputColumns $columns -Filter “duration > 10000”
Start-DbaXESmartTarget -SqlInstance sql2017 -Session deadlock_tracker -Responder $response

Author

This command was created by Chrissy LeMaire. You can find Chrissy on Twitter.

Get-Help

From PowerShell, execute Get-Help Start-DbaXESmartTarget -Detailed for more information on this function.

Source Code

Want to see the source code? View Start-DbaXESmartTarget.ps1 on GitHub
 

Related commands