|
|
|
Forum 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
|
|
|
|
|
Forum 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
|
|
|
|
|
Forum 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
|
|
|
|