DaveWentzel.com            All Things Data

Log in to SQL Server

 

this is not working code, just covers the highlights of connecting to a SQL Server from PS.
 

# Load SMO assemblies

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlEnum")

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")

# Instantiate a server object

$smoServer = New-Object -typename Microsoft.SqlServer.Management.Smo.Server -argumentlist "server"

#sql server auth

$smoServer.ConnectionContext.set_LoginSecure($FALSE)

$smoServer.ConnectionContext.set_EncryptConnection($FALSE)

$smoServer.ConnectionContext.set_Login("something")

$smoServer.ConnectionContext.set_SecurePassword("password")

#Windows auth

$smoServer.ConnectionContext.set_LoginSecure($TRUE)

 

$smoServer.ConnectionContext.ConnectionString.Split(";")

 

 

Add new comment