Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

how connect to sql server as different user using powershell ?

$
0
0
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 = $FALSEcurrently I logged in to domain as Company\poweruser1[b]I want to connect to sql server as different domain user[/b]$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.Versionas result connection was not establishedWhat am I missing?

Viewing all articles
Browse latest Browse all 467

Trending Articles