how connect to sql server as different user using powershell ?

  • Example

    $instanceName ="Host001\Server1,14002"

    $AppName = "$($ENV:computername.ToString())_$(($MyInvocation.MyCommand).Path)"

    $conn = new-object Microsoft.SqlServer.Management.Common.ServerConnection

    $conn.ServerInstance = $instanceName

    $conn.ApplicationName = $AppName

    $conn.LoginSecure = $FALSE

    currently I logged in to domain as Company\poweruser1

    I want to connect to sql server as different domain user

    $credential = Get-Credential -- at pop credential dialog box I enter user as Company\DBA and password as 123456

    $loginName = $credential.UserName

    $conn.Login = $loginName

    $conn.Password = $credential.Password

    $srv = new-object Microsoft.SqlServer.Management.Smo.Server($conn)

    Write-Host $srv.Information.Version

    as result connection was not established

    What am I missing?

  • Is it integrated authentication?

    If so then my understanding is that you need something like what is found here: http://poshcode.org/1867

    Gaz

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

  • Or maybe this will help: http://kristofmattei.be/2013/04/12/serverconnection-and-login-failed-for-user-reason-attempting-to-use-an-nt-account-name-with-sql-server-authentication/[/url]

    Gaz

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

  • Basically, I think that you have been attempting to connect using the method for SQL Server logins whereas you want to connect as a domain account.

    Gaz

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

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

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