I’m using SQL Server 2008.
I’m trying to script out all my stored procedures, and it’s very easy to do in SSMS by right clicking my database, then going to Tasks -> Generate Scripts. I set my options and all is good.
I would like to get the actual T-SQL that the script wizard is executing so that I don’t have to go through and select all of my options every single time I want to do it. I want to just open the script and hit run. Is there a way to copy the script that the wizard itself is executing? Or do I just have to do it manually every time?
You can do this with a pretty simple powershell script using the SMO Framework. You will need to have SQL Server Management Studio installed for the framework to get picked up. You should look into this further, but the basic framework will be:
You may need to alter some additional options. MSDN has a pretty thorough overview of the framework here.
Essentially the above will script out all the stored procs in a database to whatever file you specify. SMO is the framework that SSMS uses so it should be identical.