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


The default output format of Invoke-DbaDiagnosticQuery is a custom object. It can also output to CSV and Excel. However, CSV output can generate a lot of files and Excel output depends on the ImportExcel module by Doug Fike (https://github.com/dfinke/ImportExcel)

Export-DbaDiagnosticQuery can be used to convert from the default export type to the other available export types.




Converts output from Invoke-DbaDiagnosticQuery to multiple CSV files

Invoke-DbaDiagnosticQuery -SqlInstance sql2016 | Export-DbaDiagnosticQuery -Path c:\temp

Export-DbaDiagnosticQuery -InputObject $output -ConvertTo Excel
Converts output from Invoke-DbaDiagnosticQuery to Excel worksheet(s) in the Documents folder

$output = Invoke-DbaDiagnosticQuery -SqlInstance sql2016


This command was created by André Kamman. You can find André on Twitter and his blog.


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

Source Code

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

Related commands