question

DataJoe avatar image
DataJoe asked

How do you refresh instance name in script?

I have a script that echo's all the settings for CIS compliancy. Problem is I have to close and reopen SQL to get script to recognize different instance. There has to be a way to refresh this setting, I hope.
instance
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Wimbush avatar image
David Wimbush answered
I'm not clear what you want to do and what is not working. I presume you realise you can change the connection of the script to a different server without closing it? Just right click on the script window and it's in the pop-up menu under Connection. Or are you trying to run this script against all servers in a list in one go? In which case this article shows how to do that: [ http://www.mssqltips.com/sqlservertip/2086/run-sql-commands-against-multiple-sql-servers-without-cms/][1] [1]: http://www.mssqltips.com/sqlservertip/2086/run-sql-commands-against-multiple-sql-servers-without-cms/
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

JohnM avatar image JohnM commented ·
Just to add to that, if the query is in SQLCMD mode, you can use the syntax :CONNECT [ServerName\InstanceName] and it will execute the subsequent code in the context of that server.
1 Like 1 ·
DataJoe avatar image DataJoe commented ·
The answer I thought I was looking for was right click in script window and change connection. That worked awesomely. However, I am confused but intrigued by running the script across all the instances at once by adding code to script. My skill level perhaps is not enough to understand what is going on. how do you run script repetitively across all the desired instances?
0 Likes 0 ·
KenJ avatar image KenJ commented ·
That was right in the linked article. Server groups in the registered servers pane.
0 Likes 0 ·
DataJoe avatar image
DataJoe answered
Got my answers from this! Thanks so much. I put my instances in a library and registered them. I have two things to figure out but hey the whys but. If I open current script and run it does not provide output like if I select new library, open new query, paste code in new query and run it. WOW! I believe now I will have to create sub folders for each instance so entire code will run against each instance the go to next instance.!!!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.