< Back

New-DbaXESmartEmail

Mon Jan 13, 2020 1:02 pm

NAME New-DbaXESmartEmail



SYNOPSIS

This response type can be used to send an email each time an event is captured.





SYNTAX

New-DbaXESmartEmail [-SmtpServer] <String> [-Sender] <String> [-To] <System.String[]> [[-Cc] <System.String[]>]

[[-Bcc] <System.String[]>] [[-Credential] <Pscredential>] [-Subject] <String> [-Body] <String> [[-Attachment]

<String>] [[-AttachmentFileName] <String>] [[-PlainText] <String>] [[-Event] <System.String[]>] [[-Filter]

<String>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

This response type can be used to send an email each time an event is captured.





PARAMETERS

-Attachment [<String>]

Data to attach to the email message. At this time, it can be any of the fields/actions of the underlying

event. The data from the field/action is attached to the message as an ASCII stream. A single attachment is

supported.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-AttachmentFileName [<String>]

File name to assign to the attachment.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Bcc [<System.String[]>]

Address of the Bcc recipient(s).



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Body [<String>]

Body of the mail message. The body can be static text or any property taken from the underlying event. See

Subject for a description of how placeholders work.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Cc [<System.String[]>]

Address of the Cc recipient(s).



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Credential [<Pscredential>]

Credential object containing username and password used to authenticate on the SMTP server. When blank, no

authentication is performed.



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



-PlainText [<String>]

If this switch is enabled, the email will be sent in plain text. By default, HTML formatting is used.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Sender [<String>]

Sender's email address.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SmtpServer [<String>]

Address of the SMTP server for outgoing mail.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Subject [<String>]

Subject of the mail message. Accepts placeholders in the text.



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

the Event object.



For instance, a valid Subject in a configuration file looks like this: "An event of name {Name} occurred at

{collection_time}"



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-To [<System.String[]>]

Address of the To recipient(s).



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:\\>$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 $emailresponse



Sends an email each time a querytracker event is captured.



RELATED LINKS

https://dbatools.io/New-DbaXESmartEmail