Grant Fritchey wrote a Powershell script to export query plans from the plan cache into a .sqlplan file:
I’ve gone minimal on the script. I’m creating a connection to the local instance, defining a command, and returning the data into a data set. From there, since the data set consists of a single column, I’m walking through them all to export out to a file:
It’s Powershell, so it’s a short snippet.