Skip to content
Mitch Wheat edited this page Mar 20, 2018 · 15 revisions

SQLDiagCmd is a no install required, standalone executable command-line runner for Glenn Berry's SQL Server diagnostic scripts. You can simply copy the single SQLDiagCmd.exe executable to a thumbdrive along with the DMV scripts you want to run, and a batch file to contain the run options (listed below).

The motivation for writing this standalone runner?

Glenn provides Excel template files for copying the results of his excellent query scripts but I found I was spending more time copying, pasting and formatting results than I was running them! So I decided to automate this process.

SQLDiagCmd will run a specified TSQL diagnostic script file and save the results to Excel, without requiring that Excel (or Office) be installed.

How to Use

Download the diagnostic script that targets your version of SQL Server from https://www.sqlskills.com/blogs/glenn/category/dmv-queries/ and download the SQLDiagCmd.exe runner from here, or clone this repo and build the solution.

Assuming SQLDiagCmd.exe and the Diagnostic script are in the same directory, this command will execute the script:

SQLDiagCmd.exe -E -S servername -i ".\SQL Server 2016 Diagnostic Information Queries.sql" -o  c:\temp -d "DB1;DB2" -A

The command options are:

-S, --servername           Required. Server name or instance to run queries against, or a list of servers.
-E                         Use a trusted connection (Windows Authentication).
-U, --username             Username for SQL Login.
-P, --password             Password for SQL Login.
-i, --inputfile            Required. Query diagnostic file to run.
-o, --outputfolder         Required. Folder location to write results file.
                           Filename is made up of current time and servername.
-A, --autofit              Auto-fit Excel columns. 
-t, --timeout              Query timeout in seconds. Defaults to 360 seconds 
                           (for longer running queries).
-d, --databases            Semicolon separated list of specific databases to
                           examine. Separate each database with a semicolon. 
                           Do not include spaces between databases and semicolon. 
--help                     Display this help screen

This project uses EPPlus and the Command Line Parser Library.

Clone this wiki locally