title: Powershell connection string to SQL server
body: <p>Hi I'm trying to execute a Powershell on my local PC however using data from a remote SQL server.</p>
  
  <p>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?</p>
  
  <pre><code>$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 }&gt; output.ps1
  .\output.ps1
  </code></pre>