Deploying Database changes to multiple databases Part 2: Powershell

Here we are again. A little longer since Part 1 than I wanted to be, but I’ll do my best to make it worthwhile. When we spoke last, I said there were certain times when a TSQL cursor won’t work because of the type of command you are looking to run, like when you are trying to create a Stored Procedure in multiple databases. For cases like this, I recommend either using powershell or the option I will discuss in Part 3, SSIS.

With Powershell, I have created this script, called Query-Multiple, and added a lot of comments to help you to understand the thought process of why it is written the way it is and where you can add/remove your own logic. I’ve kept this very simple, so that it can help any DBA, who is novice with Powershell, to begin to use Powershell to help apply changes to multiple databases. When you run this script, it needs you to pass the path to the script that you want to run.

Please take a look at the script and let me know any questions or recommendations that you have. I’m very interested to hear what everyone thinks.