Extract SQL Server query parameters from execution plans using PowerShell
When you extract query text from a SQL Server execution plan, you’ll often end up with something like this:
Before it executes, you’ll need to declare every single parameter. Sure, you could copy them one by one from the plan… But that’s slow, repetitive and easy to mess up.
The solution: A script that extracts the parameters from the plan.
Instead of doing it manually, I wrote a script that automatically extracts parameters from a SQL Server execution plan and generates a DECLARE block for you.
How does it work?
- Save the ‘.sqlplan’ to your machine
- Run the PowerShell script with the file path as input
- It will produce a ready-to-run
DECLARE
block, and also copies it to your clipboard
- Paste the parameters above your query and you’re ready to run it, no manual edits needed
Wrapping Up
Manually pulling parameters from an execution plan? Not anymore.
This PowerShell script for SQL Server handles it for you: fast, clean, and ready to run.
No XML clicking. No copy-paste. Just speed, consistency and automation.
👉 Grab the script:
github.com/D-BArt-com/MSSQL-dba-tools
📬 Found it useful?
Share it with a fellow DBA or connect on LinkedIn.