Connect to Remote SQL Server using powershell or cmd

  • Hi

    I want to connect to Remote Sql server using powershell with username and  prompt for password and when connected i need to to run a query to retrieve data from the sql server and display as output when we run the powershell script.

    i have the query ready but unable to connect to remote server with the entered username and password, any one can help me out in connecting to remote sql server using powershell or cmd.

    Thank you

  • What part are you having trouble with?  Creating the connection string for prompting for the password?

  • iam unable to connect to remote sql server which is in different domain

    i am trying to create a batch file to retrieve data from remote sql and show data as output but i am unable to connect to it

  • Do you get any error messages?   It's difficult to help without more information

  • Firstly test connectivity, use powershell TNC to check the port is open

    “TNC IP.To.Other.Server -port 1433”

    Then I would look at DBATools and their ready made Invoke-DbaQuery, ConvertTo-DbaDataTable, Write-DbaDataTable functions to do the extract and load in a couple of lines of code.

  • Hi,

    if your sql server and your workstation are in different domains, you may start your powershell with a run as command.

    runas /netonly /user:your_domain\your_user path to powershell

    Your are not able to connect with a domain user from a different domain, without this runas command.

    We use this every day....

    Kind regards,

    Andreas

  • This was removed by the editor as SPAM

Viewing 7 posts - 1 through 6 (of 6 total)

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