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


Exports an XESession XML Template either from our repo or a file you specify. Exports to “$home\Documents\SQL Server Management Studio\Templates\XEventTemplates” by default.




Exports XE Session Template to the C:\temp\xe folder.

Export-DbaXESessionTemplate -SqlInstance sql2017 -Path C:\temp\xe

Returns a new XE Session object from sql2017 then adds an event, an action then creates it.

Get-DbaXESession -SqlInstance sql2017 -Session session_health | Export-DbaXESessionTemplate -Path C:\temp


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


From PowerShell, execute Get-Help Export-DbaXESessionTemplate -Detailed for more information on this function.

Source Code

Want to see the source code? View Export-DbaXESessionTemplate.ps1 on GitHub

Related commands