Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Created September 16, 2015 16:10
Show Gist options
  • Save mbrownnycnyc/40c138de6e4ce892f8bb to your computer and use it in GitHub Desktop.
Save mbrownnycnyc/40c138de6e4ce892f8bb to your computer and use it in GitHub Desktop.
quick SQL connectivity test with auth
#http://irisclasson.com/2013/10/16/how-do-i-query-a-sql-server-db-using-powershell-and-how-do-i-filter-format-and-output-to-a-file-stupid-question-251-255/
$connectionString = "Data Source=localhost\SQLEXPRESS;Integrated Security=false;Database=dbname;user id=sqluser;password=sqluserpassword;Connect Timeout=3;"
$sqlConn = new-object ("Data.SqlClient.SqlConnection") $connectionString
$sqlConn.Open()
$sqlcmd = New-Object System.Data.SqlClient.SqlCommand
$sqlcmd.connection = $sqlConn
$sqlcmd.commandtext = "SELECT * FROM information_schema.tables"
$sqlreader = $sqlcmd.ExecuteReader()
$table = new-object “System.Data.DataTable”
$table.Load($sqlreader)
$table
$sqlconn.Close()
$sqlcmd = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment