invoke-sqlcmd with domain user name and password

I am trying to execute below small SQL script from powershell by passing my domain user name and password..but it is throwing an error login failed for the user.

Howerver I am able to execute the same query by passing normal user 'non domain' and password. The issue is only when i am trying to connect with domain username.

Can you please suggest if there is any way to execute below query with domain user..

Invoke-Sqlcmd -query "select name from master.sys.databases" -ServerInstance "CM-NCKM-DBTST04\SQL2012" -username "sos\9venk" -password "xxxx"

Thanks

Venkat

January 15th, 2015 3:23pm

Hi,

You can't use -Username to specify a Windows account, only a SQL account. If you want to run your command as an other Windows account, you'll need to launch a PowerShell session as that user.

http://technet.microsoft.com/en-us/magazine/gg313741.aspx

Free Windows Admin Tool Kit Click here and download it now
January 15th, 2015 4:15pm

Hi Venkat,

Agree with Mike, to connect sql via powershell, you can refer to this article about authentications:

Connecting to SQL Server through Powershell

Please try to gather credentials using Get-Credential, and then use New-PSSession -Authentication CredSSP to open the pssession.

A similar discussion about this issue is for your reference:

Invoke-SQLCmd with Different Credential

If there is anything else regarding this issue, please feel free to post back.

Best Regards,

Anna Wang

January 16th, 2015 6:18am

In the first article, the poster essentially says none of the suggestions worked. May not have been the best thing to link to.
Free Windows Admin Tool Kit Click here and download it now
May 27th, 2015 4:19pm

In the first article, the poster essentially says none of the suggestions worked. May not have been the best thing to link to.

What?

May 27th, 2015 4:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics