If I said that I use Glenn Berry’s SQL Server diagnostic queries a fair bit it would be an understatement. Glenn releases versions of these very useful TSQL scripts (comprised of 50 plus queries) and a blank Excel Template to save the results in.
Rather than running each query individually, highlighting the results in SSMS and then copying and pasting to Excel, I decided to write a standalone, no install required runner that would do the donkey work for me:
- It should run from command line (or through a UI)
- It should be standalone, require no installation, and not require Excel or Office to be installed.
- It should work with new (and old) versions of his scripts, and not require updating when the scripts are updated.
- It should not require a blank excel template file.
- It should identify and run Server and database specific queries automatically.
- It should be able to target multiple databases at once.
The only (optional) alteration to Glenn’s scripts, is a small addition to the comment line which describes each query, that is used as the worksheet name (if this is missing, it uses the text at the start of the comment, but this won’t be unique due to Excel’s ridiculous limitation of having a 31 character maximum length for worksheet names!).
So, for each comment preceding a query, instead of:
-- SQL Server Services information (SQL Server 2008 R2 SP1 or greater) (Query 5)
I’ve altered to explicitly specify what text to use as the worksheet name (in bold):
-- SQL Server Services information (SQL Server 2008 R2 SP1 or greater) (Query 5)(SQL Server Services Info)
I’ve emailed Glenn to see if I can get this addition in future scripts.
You can download version 1.0 of the zipped executable from here: SQLDiagCmd.zip (targets .NET Framework 4.0)
OK, How do I run it?
Download Glenn’s diagnostic script that targets your version of SQL Server and download SQLDiagCmd.exe.
Assuming they are in the same directory:
SQLDiagCmd.exe -E -S MUTLEY -i ".\SQL Server 2008 Diagnostic Information Queries (January 2013).sql"
-o c:\temp -d "AdventureWorks2008R2;AnotherUserDatabase" -A
Typing SQLDiagCmd.exe –-help displays usage and parameters:
Usage:
SQLDiagCmd -E -S MUTLEY -i queries.sql -o C:\outputfolder -d databaselist –A
SQLDiagCmd -S MUTLEY -U username -P password -i queries.sql -o C:\outputfolder -d databaselist –A
-S, –servername |
Required. Server name or instance to run queries against. |
-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. |
-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 |
The SQLDiagCmd git repository is available at github: SQLDiagCmd
This project uses EPPlus and the Command Line Parser Library.