locked
invoke-sqlcmd with another credential RRS feed

  • Question

  • I want to run invoke-sqlcmd with other credentials in powershell.

    I tried creating newpssession but i seem  get errors.

    Any help is appreciated.

    Thank you


    Su

    • Moved by Kalman Toth Monday, May 11, 2015 11:57 PM Not T-SQL
    Monday, May 11, 2015 8:08 PM

Answers

  • Hi Su,

    When using Invoke-Sqlcmd, please note that we can't use -Username to specify a Windows account, only a SQL account. For more details about Invoke-sqlcmd authentication, please review this blog.

    If you want to run your script with an separate Windows account, you might need to gather credentials using Get-Credential, and then use New-PSSession -Authentication CredSSP to open the possession, there is a similar issue for your reference.

    Also you can post the question in the Windows PowerShell forum to get better support.

    Thanks,
    Lydia Zhang

    If you have any feedback on our support, please click here.


    Lydia Zhang
    TechNet Community Support



    Thursday, May 14, 2015 3:16 AM

All replies

  •  Create a SQL login to use then use Invoke-SQL as is with the -username and -password options.
    Monday, May 11, 2015 8:33 PM
  • I have an mixed( windows and sqlserver authentication)mode.

    I want a separate windows account to execute sqlscript .

    I get this error

    Invoke-Sqlcmd : Login failed for user

    Please let me know if its possible.


    Su


    • Edited by Susan Lan Monday, May 11, 2015 8:38 PM more details
    Monday, May 11, 2015 8:37 PM
  • Hi Su,

    When using Invoke-Sqlcmd, please note that we can't use -Username to specify a Windows account, only a SQL account. For more details about Invoke-sqlcmd authentication, please review this blog.

    If you want to run your script with an separate Windows account, you might need to gather credentials using Get-Credential, and then use New-PSSession -Authentication CredSSP to open the possession, there is a similar issue for your reference.

    Also you can post the question in the Windows PowerShell forum to get better support.

    Thanks,
    Lydia Zhang

    If you have any feedback on our support, please click here.


    Lydia Zhang
    TechNet Community Support



    Thursday, May 14, 2015 3:16 AM