Link to home
Start Free TrialLog in
Avatar of Ward Minson
Ward Minson

asked on

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.
Avatar of Qlemo
Qlemo
Flag of Germany image

You can use EXEC with a server link to execute remote.
Avatar of Ward Minson
Ward Minson

ASKER

Qlemo
could you show me an example of what you are suggesting?
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.
is there any other way with out creating a linked server?
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am planning on creating the connection string dynamically and then run the alter on the  server that needs the change.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use OPENDATASOURCE. The complete guide to this command is here in MSDN.
this worked with my original script very well thank you.