Author | Chrissy LeMaire (@cl), netnerds.net |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Get-DbaExecutionPlan on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaExecutionPlan.
Gets execution plans and metadata
Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan
Thanks to following for the queries:
https://www.simple-talk.com/sql/t-sql-programming/dmvs-for-query-plan-metadata/
http://www.scarydba.com/2017/02/13/export-plans-cache-sqlplan-file/
Get-DbaExecutionPlan
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <Object[]>]
[[-ExcludeDatabase] <Object[]>]
[[-SinceCreation] <DateTime>]
[[-SinceLastExecution] <DateTime>]
[-ExcludeEmptyQueryPlan]
[-Force]
[-EnableException]
[<CommonParameters>]
PS C:\> Get-DbaExecutionPlan -SqlInstance sqlserver2014a
Gets all execution plans on sqlserver2014a
PS C:\> Get-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution '2016-07-01 10:47:00'
Gets all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM.
PS C:\> Get-DbaExecutionPlan -SqlInstance sqlserver2014a, sql2016 -Exclude db1 | Format-Table
Gets execution plan info for all databases except db1 on sqlserver2014a and sql2016 and makes the output pretty
PS C:\> Get-DbaExecutionPlan -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force
Gets super detailed information for execution plans on only for AdventureWorks2014 and pubs
PS C:\> $servers = "sqlserver2014a","sql2016t"
PS C:\> $servers | Get-DbaExecutionPlan -Force
Gets super detailed information for execution plans on sqlserver2014a and sql2016
The target SQL Server instance or instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
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 | |
Required | False |
Pipeline | false |
Default Value |
Return execution plans and metadata for only specific databases.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Return execution plans and metadata for all but these specific databases
Alias | |
Required | False |
Pipeline | false |
Default Value |
Datetime object used to narrow the results to a date
Alias | |
Required | False |
Pipeline | false |
Default Value |
Datetime object used to narrow the results to a date
Alias | |
Required | False |
Pipeline | false |
Default Value |
Exclude results with empty query plan
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Returns a ton of raw information about the execution plans
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 |