< Back

Get-DbaExecutionPlan

Mon Jan 13, 2020 11:04 am

NAME Get-DbaExecutionPlan



SYNOPSIS

Gets execution plans and metadata





SYNTAX

Get-DbaExecutionPlan [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>] [[-SinceCreation]

<Datetime>] [[-SinceLastExecution] <Datetime>] [-ExcludeEmptyQueryPlan <Switch>] [-Force <Switch>]

[-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Gets execution plans and metadata. Can pipe to Export-DbaExecutionPlan



Thanks to following for the queries:



https://www.simple-talk.com/sql/t-sql-p ... -metadata/



http://www.scarydba.com/2017/02/13/expo ... plan-file/





PARAMETERS

-Database [<System.Object[]>]

Return execution plans and metadata for only specific databases.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeDatabase [<System.Object[]>]

Return execution plans and metadata for all but these specific databases



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeEmptyQueryPlan [<Switch>]

Exclude results with empty query plan



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

Returns a ton of raw information about the execution plans



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SinceCreation [<Datetime>]

Datetime object used to narrow the results to a date



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SinceLastExecution [<Datetime>]

Datetime object used to narrow the results to a date



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Performance

Author: Chrissy LeMaire (@cl), netnerds.net



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-DbaExecutionPlan -SqlInstance sqlserver2014a



Gets all execution plans on sqlserver2014a

-------------------------- EXAMPLE 2 --------------------------



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.

-------------------------- EXAMPLE 3 --------------------------



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

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-DbaExecutionPlan -SqlInstance sql2014 -Database AdventureWorks2014, pubs -Force



Gets super detailed information for execution plans on only for AdventureWorks2014 and pubs

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>$servers = "sqlserver2014a","sql2016t"



PS C:\\> $servers | Get-DbaExecutionPlan -Force



Gets super detailed information for execution plans on sqlserver2014a and sql2016



RELATED LINKS

https://dbatools.io/Get-DbaExecutionPlan