dbatools is a free PowerShell module with over 300 SQL Server administration, best practice and migration commands included.

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Uses a slightly modified version of sp_SQLskills_ConvertTraceToExtendedEvents.sql to convert Traces to Extended Events.

T-SQL code by: Jonathan M. Kehayias, SQLskills.com. T-SQL can be found in this module directory and at
SQL Skills




Converts Trace with ID 2 to a Session named Test on SQL Server instances named sql2017 and sql2012 and creates the Session on each respective server.

Get-DbaTrace -SqlInstance sql2017, sql2012 | Where Id -eq 2 | ConvertTo-DbaXESession -Name ‘Test’

Converts selected traces on sql2014 to sessions, creates the session, and starts it.

Get-DbaTrace -SqlInstance sql2014 | Out-GridView -PassThru | ConvertTo-DbaXESession -Name ‘Test’ | Start-DbaXESession

Converts trace ID 1 on sql2014 to an Extended Event and outputs the resulting T-SQL.

Get-DbaTrace -SqlInstance sql2014 | Where Id -eq 1 | ConvertTo-DbaXESession -Name ‘Test’ -OutputScriptOnly


This command was created by Chrissy LeMaire. You can find Chrissy on Twitter.


From PowerShell, execute Get-Help ConvertTo-DbaXESession -Detailed for more information on this function.

Source Code

Want to see the source code? View ConvertTo-DbaXESession.ps1 on GitHub

Related commands