Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

use SQL authentication on the provided powershell scripts Expand / Collapse
Author
Message
Posted Monday, May 31, 2010 10:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 01, 2010 10:19 PM
Points: 3, Visits: 28
Hi Cmille 19. I have tried both powershell scripts without any problems on SQL DBs who are members of our Windows domain. However, I need to connect to a MSSQL DB that is not a member of our domain. Can you give us PS1 using SQL authentication? THanks in advance
Post #930521
Posted Monday, May 31, 2010 11:37 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 01, 2010 10:19 PM
Points: 3, Visits: 28
Hi again Cmille19,

I am using the ff ps to successfully connect to an instance using sql authentication. But can't seem to integrate this with the PS scripts you provided. Hope you can help me out. THanks again.


param
(
[string]$serverName = "instance_name",
[switch]$verbose,
[switch]$debug
)

function main()
{
if ($verbose) {$VerbosePreference = "Continue"}
if ($debug) {$DebugPreference = "Continue"}
Connect-MSSQL-IPSQLAuth $serverName
}

function Connect-MSSQL-IPSQLAuth($serverName)
{
trap [Exception]
{
write-error $("TRAPPED: " + $_.Exception.Message);
continue;
}

[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")

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

$smoServer.ConnectionContext.set_LoginSecure($FALSE)

$LoginCredentials = Get-Credential

$Login = $LoginCredentials.UserName -replace("\\","")

$smoServer.ConnectionContext.set_EncryptConnection($FALSE)
$smoServer.ConnectionContext.set_Login($Login)
$smoServer.ConnectionContext.set_SecurePassword($LoginCredentials.Password)

# The ff tests a successful db connect
cls
Write-Host Your connection string contains these values:
Write-Host
Write-Host $smoServer.ConnectionContext.ConnectionString.Split(";")
Write-Host

# List info about databases on the instance.
Write-Host "Databases on $serverName "
Write-Host
foreach ($Database in $smoServer.Databases)
{
write-host "Database Name : " $Database.Name
write-host "Owner : " $Database.Owner
write-host
}
}

main
Post #930532
Posted Tuesday, June 01, 2010 10:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, July 01, 2010 10:19 PM
Points: 3, Visits: 28
I guess singling out cmille to reply isn't working in my favor...

Can anyone help please
Post #931087
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse