< Back

Export-DbaExecutionPlan

Mon Jan 13, 2020 9:54 am

NAME Export-DbaExecutionPlan



SYNOPSIS

Exports execution plans to disk.





SYNTAX

Export-DbaExecutionPlan [-Database <System.Object[]>] [-ExcludeDatabase <System.Object[]>] [-EnableException

<Switch>] [<CommonParameters>]



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

<Pscredential>] [-Database <System.Object[]>] [-ExcludeDatabase <System.Object[]>] [-Path <String>]

[-SinceCreation <Datetime>] [-SinceLastExecution <Datetime>] [-EnableException <Switch>] [<CommonParameters>]



Export-DbaExecutionPlan [-Database <System.Object[]>] [-ExcludeDatabase <System.Object[]>] [-Path <String>]

-InputObject <System.Object[]> [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

Exports execution plans to disk. Can pipe from Get-DbaExecutionPlan



Thanks to



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



and



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



for the idea and query.





PARAMETERS

-Database [<System.Object[]>]

The database(s) to process - this list is auto-populated from the server. If unspecified, all databases will

be processed.



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[]>]

The database(s) to exclude - this list is auto-populated from the server



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-InputObject [<System.Object[]>]

Internal parameter



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Path [<String>]

The directory where all of the sqlxml files will be exported



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, ExecutionPlan

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:\\>Export-DbaExecutionPlan -SqlInstance sqlserver2014a -Path C:\\Temp



Exports all execution plans for sqlserver2014a. Files saved in to C:\\Temp

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



PS C:\\>Export-DbaExecutionPlan -SqlInstance sqlserver2014a -Database db1, db2 -SinceLastExecution '2016-07-01

10:47:00' -Path C:\\Temp



Exports all execution plans for databases db1 and db2 on sqlserver2014a since July 1, 2016 at 10:47 AM. Files

saved in to C:\\Temp

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



PS C:\\>Get-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\\Temp



Gets all execution plans for sqlserver2014a. Using Pipeline exports them all to C:\\Temp

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



PS C:\\>Get-DbaExecutionPlan -SqlInstance sqlserver2014a | Export-DbaExecutionPlan -Path C:\\Temp -WhatIf



Gets all execution plans for sqlserver2014a. Then shows what would happen if the results where piped to

Export-DbaExecutionPlan



RELATED LINKS

https://dbatools.io/Export-DbaExecutionPlan