< Back

New-DbaXESmartQueryExec

Mon Jan 13, 2020 1:02 pm

NAME New-DbaXESmartQueryExec



SYNOPSIS

This response type executes a T-SQL command against a target database whenever an event is recorded.





SYNTAX

New-DbaXESmartQueryExec [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[[-SqlCredential] <Pscredential>] [[-Database] <String>] [[-Query] <String>] [-EnableException <Switch>] [[-Event]

<System.String[]>] [[-Filter] <String>] [<CommonParameters>]





DESCRIPTION

This response type executes a T-SQL command against a target database whenever an event is recorded.





PARAMETERS

-Database [<String>]

Specifies the name of the database that contains the target table.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Event [<System.String[]>]

Each Response can be limited to processing specific events, while ignoring all the other ones. When this

attribute is omitted, all events are processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Filter [<String>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Query [<String>]

The T-SQL command to execute. This string can contain placeholders for properties taken from the events.



Placeholders are in the form {PropertyName}, where PropertyName is one of the fields or actions available in

the Event object.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL

Server version 2008 or higher.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: ExtendedEvent, XE, XEvent, SmartTarget

Author: Chrissy LeMaire (@cl) | SmartTarget by Gianluca Sartori (@spaghettidba)



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



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.



RELATED LINKS

https://dbatools.io/New-DbaXESmartQueryExec