Alter logins accross many servers without cms

is it possible to do an 'ALTER LOGIN [loginname] DISABLE' using either openrowsource or opendatasource?

And if so how can i do this?

I have a list of servers that i need to change all users with a specific name to disabled.
Ward MinsondeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
You can use EXEC with a server link to execute remote.
0
Ward MinsondeveloperAuthor Commented:
Qlemo
could you show me an example of what you are suggesting?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
declare @name = nvarchar(100)
set @name = 'whoever'
exec ('ALTER LOGIN ' + @name + ' DISABLE') at LinkedServerName

Open in new window

You can code the user name literally into the command, of course, if you don't need it to be variable.
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Ward MinsondeveloperAuthor Commented:
is there any other way with out creating a linked server?
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Don't think it is of much use, as you have to provide connection info literally (no var allowed), but here it is:
exec opendatasource('SQLNCLI', 'Server=TheServer\TheInstance; Integrated Security=SSPI ').master.dbo.sp_executesql N'alter login JamesBond disable'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ward MinsondeveloperAuthor Commented:
I am planning on creating the connection string dynamically and then run the alter on the  server that needs the change.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Then you'll have to create a dynamic SQL string containing the complete command starting with opendatasource, and execute that with EXEC or sp_executesql. As you should know, neither opendatasource nor openrowset allow dynamic connection strings.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
You can use OPENDATASOURCE. The complete guide to this command is here in MSDN.
0
Ward MinsondeveloperAuthor Commented:
this worked with my original script very well thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.