May 31, 2010 at 10:35 pm
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
May 31, 2010 at 11:37 pm
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
June 1, 2010 at 10:22 pm
I guess singling out cmille to reply isn't working in my favor...:hehe:
Can anyone help please
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy