< Back

Start-DbaXESmartTarget

Mon Jan 13, 2020 5:53 pm

NAME Start-DbaXESmartTarget



SYNOPSIS

XESmartTarget runs as a client application for an Extended Events session running on a SQL Server instance.





SYNTAX

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

[[-SqlCredential] <Pscredential>] [[-Database] <String>] [-Session] <String> [-FailOnProcessingError <Switch>]

[[-Responder] <System.Object[]>] [[-Template] <System.String[]>] [-NotAsJob <Switch>] [-EnableException <Switch>]

[<CommonParameters>]





DESCRIPTION

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 https://github.com/spaghettidba/XESmartTarget/wiki





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



-FailOnProcessingError [<Switch>]

If this switch is enabled, the a processing error will trigger a failure.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-NotAsJob [<Switch>]

If this switch is enabled, output will be sent to screen indefinitely. BY default, a job will be run in the

background.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Responder [<System.Object[]>]

The list of responses can include zero or more Response objects, each to be configured by specifying values

for their public members.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Session [<String>]

Name of the Extended Events session to attach to.



You can monitor a single session with an instance of XESmartTarget. In case you need to perform action on

multiple sessions, run an additional instance of XESmartTarget, with its own configuration file.



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



-Template [<System.String[]>]

Path to the dbatools built-in templates



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.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>$response = New-DbaXESmartQueryExec -SqlInstance sql2017 -Database dbadb -Query "update table set whatever

= 1"



PS C:\\>$params = @{

>> SmtpServer = "smtp.ad.local"

>> To = "admin@ad.local"

>> Sender = "reports@ad.local"

>> Subject = "Query executed"

>> Body = "Query executed at {collection_time}"

>> Attachment = "batch_text"

>> AttachmentFileName = "query.sql"

>> }

PS C:\\> $emailresponse = New-DbaXESmartEmail @params

PS C:\\> Start-DbaXESmartTarget -SqlInstance sql2017 -Session querytracker -Responder $response, $emailresponse



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

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>$columns = "cpu_time", "duration", "physical_reads", "logical_reads", "writes", "row_count", "batch_text"



PS C:\\> $response = New-DbaXESmartTableWriter -SqlInstance sql2017 -Database dbadb -Table deadlocktracker

-OutputColumns $columns -Filter "duration > 10000"

PS C:\\> Start-DbaXESmartTarget -SqlInstance sql2017 -Session deadlock_tracker -Responder $response



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



RELATED LINKS

https://dbatools.io/Start-DbaXESmartTarget