Created
December 6, 2017 09:05
-
-
Save ghotz/13726ced84c945d354e3a5cd80dfbcd9 to your computer and use it in GitHub Desktop.
Execute query with SqlCmd variables and save SQL Server execution plan example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$SqlCmdVariables = "DatabaseName=master", "ColumnName=name"; | |
$Results = (Invoke-Sqlcmd -ServerInstance "localhost\sql2017" -Query "SET STATISTICS XML ON; SELECT `$(ColumnName) FROM sys.databases WHERE [name] = '`$(DataBaseName)';" -Variable $SqlCmdVariables -MaxCharLength 10MB); | |
$Plan = [xml]$Results[$Results.GetUpperBound(0)].Item(0); | |
$Plan.Save("C:\temp\test.sqlplan"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment