Author | Andre Kamman (@AndreKamman), andrekamman.com |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Invoke-DbaDiagnosticQuery on GitHub.
Want to see the Bill Of Health for this command? Check out Invoke-DbaDiagnosticQuery.
Invoke-DbaDiagnosticQuery runs the scripts provided by Glenn Berry's DMV scripts on specified servers
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:
https://glennsqlperformance.com/resources/
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] <DbaInstanceParameter[]>
[-Database <Object[]>]
[-ExcludeDatabase <Object[]>]
[-ExcludeQuery <Object[]>]
[-SqlCredential <PSCredential>]
[-Path <FileInfo>]
[-QueryName <String[]>]
[-UseSelectionHelper]
[-InstanceOnly]
[-DatabaseSpecific]
[-ExcludeQueryTextColumn]
[-ExcludePlanColumn]
[-NoColumnParsing]
[-OutputPath <String>]
[-ExportQueries]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance sql2016
Run the selection made by the user on the Sql Server instance specified.
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance sql2016 -UseSelectionHelper | Export-DbaDiagnosticQuery -Path C:\temp\gboutput
Provides a grid view 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.
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance localhost -ExportQueries -OutputPath "C:\temp\DiagnosticQueries"
Export All Queries to Disk
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance localhost -DatabaseSpecific -ExportQueries -OutputPath "C:\temp\DiagnosticQueries"
Export Database Specific Queries for all User Dbs
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance localhost -DatabaseSpecific -DatabaseName 'tempdb' -ExportQueries -OutputPath "C:\temp\DiagnosticQueries"
Export Database Specific Queries For One Target Database
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance localhost -DatabaseSpecific -DatabaseName 'tempdb' -ExportQueries -OutputPath "C:\temp\DiagnosticQueries" -QueryName 'Database-scoped Configurations'
Export Database Specific Queries For One Target Database and One Specific Query
PS C:\> Invoke-DbaDiagnosticQuery -SqlInstance localhost -UseSelectionHelper
Choose Queries To Export
PS C:\> [PSObject[]]$results = Invoke-DbaDiagnosticQuery -SqlInstance localhost -WhatIf
Parse the appropriate diagnostic queries by connecting to server, and instead of running them, return as [PSCustomObject[]] to work with further
PS C:\> $results = Invoke-DbaDiagnosticQuery -SqlInstance Sql2017 -DatabaseSpecific -QueryName 'Database-scoped Configurations' -DatabaseName TestStuff
Run diagnostic queries targeted at specific database, and only run database level queries against this database.
The target SQL Server instance or instances. Can be either a string or SMO server
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
The database(s) to process. If unspecified, all databases will be processed
Alias | DatabaseName |
Required | False |
Pipeline | false |
Default Value |
The database(s) to exclude
Alias | |
Required | False |
Pipeline | false |
Default Value |
The Queries to exclude
Alias | |
Required | False |
Pipeline | false |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | Credential |
Required | False |
Pipeline | false |
Default Value |
Alternate path for the diagnostic scripts
Alias | |
Required | False |
Pipeline | false |
Default Value |
Only run specific query
Alias | |
Required | False |
Pipeline | false |
Default Value |
Provides a grid view with all the queries to choose from and will run the selection made by the user on the Sql Server instance specified.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Run only instance level queries
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Run only database level queries
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Use this switch to exclude the [Complete Query Text] column from relevant queries
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Use this switch to exclude the [Query Plan] column from relevant queries
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Does not parse the [Complete Query Text] and [Query Plan] columns and disregards the ExcludeQueryTextColumn and NoColumnParsing switches
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Directory to parsed diagnostics queries to. This will split them based on server, database name, and query.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Use this switch to export the diagnostic queries to sql files. Instead of running the queries, the server will be evaluated to find the appropriate queries to run based on SQL Version.
These sql files will then be created in the OutputDirectory
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Shows what would happen if the command would execute, but does not actually perform the command
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
Prompts to confirm certain actions
Alias | cf |
Required | False |
Pipeline | false |
Default Value |