Execute SQL Script on remote server with another windows account

  • Hi All,

    I have a set of SQL server Instances in another domain connected to my machine. These instances use windows authentication to login and all the instances use different accounts.

    I am trying to come up with a script which can run on all the instances either with Powershell/Vbs/Batch files, that can connect to each of theses instances and execute a SQL script but don't know how to switch windows account for each sql execution. Any help or at least pointing me in the right direction would help.

    Please note that my ID is like DomainA\User1 but other servers have sysadmin accounts like DomainB\UserX, DomainC\UserY.

    Thanks for your help

  • You could use RunAs because you are trying to use different technologies. If you look at the help for it you can even securely save the credentials on a machine and use the /savecred parameter to indicate that a password does not need to be entered.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • Thanks for your reply Gary

    I am not trying to use different technologies. Only one of these is sufficient. Just want to know which one.

    can u elaborate a bit on runas option and how to save credentials as i have more than a thousand servers with different windows user names and password Or may be a link which explains how to use them.

    Thanks again for ur help

    🙂

  • To be honest I just knew it was there and ran RUNAS /? on the command line.

    There are all sorts of options such as launching from C#.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

  • You can save credential using /savecred switch.

    To get the list of switches which runas offer, you can look at the help.

    Thanks.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply