commands

^

Export-DbaXESession

Author Patrick Flynn (@sqllensman)
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Export-DbaXESession on GitHub.
Want to see the Bill Of Health for this command? Check out Export-DbaXESession.

Synopsis

Exports Extended Events creation script to a T-SQL file or console.

Description

Exports script to create Extended Events Session to sql file or console.

Syntax

Export-DbaXESession
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-InputObject] <Session[]>]
    [[-Session] <String[]>]
    [[-Path] <String>]
    [[-FilePath] <String>]
    [[-Encoding] <String>]
    [-Passthru]
    [[-BatchSeparator] <String>]
    [-NoPrefix]
    [-NoClobber]
    [-Append]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Export-DbaXESession -SqlInstance sourceserver -Passthru

Exports a script to create all Extended Events Sessions on sourceserver to the console
Will include prefix information containing creator and datetime. and uses the default value for BatchSeparator value from configuration Formatting.BatchSeparator

Example: 2
PS C:\> Export-DbaXESession -SqlInstance sourceserver

Exports a script to create all Extended Events Sessions on sourceserver. As no Path was defined - automatically determines filename based on the Path.DbatoolsExport configuration setting, current
time and server name like Servername-YYYYMMDDhhmmss-sp_configure.sql
Will include prefix information containing creator and datetime. and uses the default value for BatchSeparator value from configuration Formatting.BatchSeparator

Example: 3
PS C:\> Export-DbaXESession -SqlInstance sourceserver -FilePath C:\temp

Exports a script to create all Extended Events Sessions on sourceserver to the directory C:\temp using the default name format of Servername-YYYYMMDDhhmmss-sp_configure.sql
Will include prefix information containing creator and datetime. and uses the default value for BatchSeparator value from configuration Formatting.BatchSeparator

Example: 4
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Export-DbaXESession -SqlInstance sourceserver -SqlCredential $cred -FilePath C:\temp\EEvents.sql -BatchSeparator "" -NoPrefix -NoClobber

Exports a script to create all Extended Events Sessions on sourceserver to the file C:\temp\EEvents.sql.
Will exclude prefix information containing creator and datetime and does not include a BatchSeparator
Will not overwrite file if it already exists

Example: 5
PS C:\> 'Server1', 'Server2' | Export-DbaXESession -FilePath 'C:\Temp\EE.sql' -Append

Exports a script to create all Extended Events Sessions for Server1 and Server2 using pipeline.
Writes to a single file using the Append switch

Example: 6
PS C:\> Get-DbaXESession -SqlInstance Server1, Server2 -Session system_health | Export-DbaXESession -Path 'C:\Temp'

Exports a script to create the System_Health Extended Events Sessions for Server1 and Server2 using pipeline.
Write to the directory C:\temp using the default name format of Servername-YYYYMMDDhhmmss-sp_configure.sql
Will include prefix information containing creator and datetime. and uses the default value for BatchSeparator value from configuration Formatting.BatchSeparator

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input.
Server version must be SQL Server version 2008 or higher.

Alias
Required False
Pipeline true (ByValue)
Default Value
-SqlCredential

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
-InputObject

A SQL Management Object - Microsoft.SqlServer.Management.XEvent.Session such as the one returned from Get-DbaSession

Alias
Required False
Pipeline true (ByValue)
Default Value
-Session

The Extended Event Session(s) to process. If unspecified, all Extended Event Sessions will be processed. This is ignored if An input object from Get-DbaSession is specified

Alias
Required False
Pipeline false
Default Value
-Path

Specifies the directory where the file or files will be exported.

Alias
Required False
Pipeline false
Default Value (Get-DbatoolsConfigValue -FullName 'Path.DbatoolsExport')
-FilePath

Specifies the full file path of the output file.
If FilePath is specified and more than one Server is in input then -Append parameter is required to avoid overwriting data

Alias OutFile,FileName
Required False
Pipeline false
Default Value
-Encoding

Specifies the file encoding. The default is UTF8.
Valid values are:
-- ASCII: Uses the encoding for the ASCII (7-bit) character set.
-- BigEndianUnicode: Encodes in UTF-16 format using the big-endian byte order.
-- Byte: Encodes a set of characters into a sequence of bytes.
-- String: Uses the encoding type for a string.
-- Unicode: Encodes in UTF-16 format using the little-endian byte order.
-- UTF7: Encodes in UTF-7 format.
-- UTF8: Encodes in UTF-8 format.
-- Unknown: The encoding type is unknown or invalid. The data can be treated as binary.

Alias
Required False
Pipeline false
Default Value UTF8
Accepted Values ASCII,BigEndianUnicode,Byte,String,Unicode,UTF7,UTF8,Unknown
-Passthru

Output script to console

Alias
Required False
Pipeline false
Default Value False
-BatchSeparator

Batch separator for scripting output. Uses the value from configuration Formatting.BatchSeparator by default. This is normally "GO"

Alias
Required False
Pipeline false
Default Value (Get-DbatoolsConfigValue -FullName 'Formatting.BatchSeparator')
-NoPrefix

If this switch is used, the scripts will not include prefix information containing creator and datetime.

Alias
Required False
Pipeline false
Default Value False
-NoClobber

Do not overwrite file. Only required if FilePath is specified

Alias
Required False
Pipeline false
Default Value False
-Append

Append to file. Only required if FilePath is specified

Alias
Required False
Pipeline false
Default Value False
-EnableException

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