Share via

Run query on Multiple Sql Server

Pds 46 Reputation points
2021-11-15T16:55:52.287+00:00

Hello,
I am looking to run single query on Multiple Sql Server instances as I can use SSMS to register all the servers or run in CMD but I have almost 300+ servers so looking better way to add servers via scripting.

Thank you and appreciate your help!

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

Tom Phillips 17,786 Reputation points
2021-11-15T17:05:06.407+00:00

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Pds 46 Reputation points
    2021-11-17T15:53:36.937+00:00

    Cathy,
    SqlCmd good but I have type each server connect command so for connecting to 100+ servers I have to do manually v/s PowerShell script which Tom mentioned.

    Was this answer helpful?


  2. CathyJi-MSFT 22,431 Reputation points Microsoft External Staff
    2021-11-16T01:08:07.09+00:00

    Hi @Pds ,

    You can also try to run a script against several servers using SQLCMD from command prompt. Please read the part two in this blog.

    In addition, if the response from Tom is the solution that you want, please mark the useful reply as answer, it will benefit all community members who are having this similar issue. Your contribution is highly appreciated.

    Was this answer helpful?

    0 comments No comments

  3. Pds 46 Reputation points
    2021-11-15T23:50:53.517+00:00

    Thanks Tom, it was very useful.

    I was running other PowerShell query but giving me trouble but this was very straight forward.

    Thanks for quick response.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.