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


Invoke-DbaDiagnosticQuery runs the scripts provided by Glenn Berry’s DMV scripts on specified servers. It is most often used in conjunction with Export-DbaDiagnosticQuery.

By default, Invoke-DbaDiagnosticQuery runs all queries and outputs to the console. You can use the -UseSelectionHelper switch, however, to select only specific queries to run.

This is the main function of the SQL Server Diagnostic Queries related functions in dbatools. The diagnostic queries are developed and maintained by Glenn Berry and they can be found here along with a lot of documentation.

The most recent version of the diagnostic queries are included in the dbatools module. But it is possible to download a newer set or a specific version to an alternative location and parse and run those scripts. It will run all or a selection of those scripts on one or multiple servers and return the result as a PowerShell Object



Invoke-DbaDiagnosticQuery -SqlInstance sql2016

Run the selection made by the user on the Sql Server instance specified.

Invoke-DbaDiagnosticQuery -SqlInstance sql2016 -UseSelectionHelper | Export-DbaDiagnosticQuery -Path C:\temp\gboutput

Provides a GridView with all the queries to choose from and will run the selection made by the user on the SQL Server instance specified. Then it will export the results to Export-DbaDiagnosticQuery which exports the resulting queries to C:\temp\gboutput in CSV format.


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

Source Code

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

Related commands