Author | Chrissy LeMaire (@cl) , SmartTarget by Gianluca Sartori (@spaghettidba) |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out New-DbaXESmartQueryExec on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaXESmartQueryExec.
This response type executes a T-SQL command against a target database whenever an event is recorded.
This response type executes a T-SQL command against a target database whenever an event is recorded.
New-DbaXESmartQueryExec
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String>]
[[-Query] <String>]
[-EnableException]
[[-Event] <String[]>]
[[-Filter] <String>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> $response = New-DbaXESmartQueryExec -SqlInstance sql2017 -Database dbadb -Query "update table set whatever = 1"
PS C:\> Start-DbaXESmartTarget -SqlInstance sql2017 -Session deadlock_tracker -Responder $response
Executes a T-SQL command against dbadb on sql2017 whenever a deadlock event is recorded.
The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2008 or higher.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the name of the database that contains the target table.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The T-SQL command to execute. This string can contain placeholders for properties taken from the events.
Placeholders are in the form , where PropertyName is one of the fields or actions available in the Event object.
Alias | |
Required | False |
Pipeline | false |
Default Value |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Each Response can be limited to processing specific events, while ignoring all the other ones. When this attribute is omitted, all events are processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
You can specify a filter expression by using this attribute. The filter expression is in the same form that you would use in a SQL query. For example, a valid example looks like this: duration >
10000 AND cpu_time > 10000
Alias | |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |