title: Powershell to execute SQL SCRIPTS
body: <p>anyone know how to rewrite below code, so it can invoke sql script. For instance, instead of put 'SELECT @@SERVERNAME AS ServerName' in the powershell script, I would like to put it into sql file.</p>
  
  <pre><code>$Path = "D:\AdminStuff\PowerShell\Password\Password.txt"
  $uid = 'sa'
  $pwd = Get-Content D:\AdminStuff\PowerShell\Password\Password.txt | ConvertTo-SecureString
  $pwd.MakeReadOnly()
  
  
  $creds = New-Object System.Data.SqlClient.SqlCredential($uid,$pwd)
  
  $con = New-Object System.Data.SqlClient.SqlConnection
  $con.ConnectionString = "Server=SLB-CLMFZ52;Database=master;"
  $con.Credential = $creds
  $con.Open()
  
  $sql = "SELECT @@SERVERNAME AS ServerName"
  
  $cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$con)
  $rdr = $cmd.ExecuteReader()
  while($rdr.Read())
  {
   $rdr["ServerName"].ToString()
  }
  
  
  $con.Close()
  </code></pre>