Hi I'm trying to execute a Powershell on my local PC however using data from a remote SQL server.
I have script like this. It's wrong because I haven't stated the username and password to log on to the server. Could anyone tell me the correct format of doing that?
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=10.10.1.34;Database=AMSDataWarehouseTest;user id=YQBGantt;password=123yqbgantt"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "YQBreport1"
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$SQLResult =$DataSet.Tables[0]
$commands = $SQLResult | foreach-object -process { $_.output }> output.ps1
.\output.ps1
Set-PSDebug -Trace 1. NB. if the connection was failing due to authentication you would get an immediate error.