Created
September 16, 2015 16:10
-
-
Save mbrownnycnyc/40c138de6e4ce892f8bb to your computer and use it in GitHub Desktop.
quick SQL connectivity test with auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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