Run SQL Query on Multiple Servers Using PowerShell – Serially

How to execute a sql query on multiple servers using PowerShell
Spread the love

As a database administrator, often I have to fetch some metadata from all the SQLServers that we have. Other times, I have to execute some DDL or DML on all the servers.

In this blog and shared video, I show how to write a multiple server PowerShell script where server list source could range from raw text files to some inventory-based query result.

Below is the script used in the above video tutorial.


There are many similar scripts present in the SQLMonitor tool. For example, check-instance-availability.ps1 connects to many SQLServers in parallel threads to check their availability as part of monitoring.

I hope this will be helpful. If you like the blog, do like and subscribe. Thanks.

3 Comments

  1. Jay

    Hi Ajay, thank you for the script. It is very useful. In your youtube video you have a link for part 2 to run in parallel, But the link takes you back to this page for serial. Is there a video for parallel?

    • Glad you liked it. I have not created video on Parallel execution.
      Since you mentioned it, I’ll create now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.