commands

^

Watch-DbaXESession

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

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

Synopsis

Watch live XEvent Data as it happens

Description

Watch live XEvent Data as it happens. This command runs until you stop the session, kill the PowerShell session, or Ctrl-C.

Thanks to Dave Mason (@BeginTry) for some straightforward code samples https://itsalljustelectrons.blogspot.be/2017/01/SQL-Server-Extended-Event-Handling-Via-Powershell.html

Syntax

Watch-DbaXESession
    [[-SqlInstance] <DbaInstanceParameter>]
    [[-SqlCredential] <PSCredential>]
    [[-Session] <String>]
    [[-InputObject] <Session[]>]
    [-Raw]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Watch-DbaXESession -SqlInstance sql2017 -Session system_health

Shows events for the system_health session as it happens.

Example: 2
PS C:\> Watch-DbaXESession -SqlInstance sql2017 -Session system_health | Export-Csv -NoTypeInformation -Path C:\temp\system_health.csv

Exports live events to CSV. Ctrl-C may not not cancel out of it - fastest way is to stop the session.

Example: 3
PS C:\> Get-DbaXESession -SqlInstance sql2017 -Session system_health | Start-DbaXESession | Watch-DbaXESession | Export-Csv -NoTypeInformation -Path C:\temp\system_health.csv

Exports live events to CSV. Ctrl-C may not not cancel out of this. The fastest way to do so is to stop the session.

Optional Parameters

-SqlInstance

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 False
Pipeline false
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
-Session

Only return a specific session. Options for this parameter are auto-populated from the server.

Alias Name
Required False
Pipeline false
Default Value
-InputObject

Accepts an XESession object returned by Get-DbaXESession.

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

If this switch is enabled, the enumeration object is returned.

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