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