Created
May 5, 2017 02:00
-
-
Save isaksky/3c3397fc29964dc0573d355f6f3ad9b6 to your computer and use it in GitHub Desktop.
Powershell Query SQL
This file contains 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
function sq | |
{ | |
param([string]$Query) | |
$SQLServer = "ISAK-NEW\SQLEXPRESS" | |
$SQLDBName = "AdventureWorks2014" | |
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection | |
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True;" | |
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand | |
$SqlCmd.CommandText = $Query | |
$SqlCmd.Connection = $SqlConnection | |
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter | |
$SqlAdapter.SelectCommand = $SqlCmd | |
$ds = New-Object System.Data.DataSet | |
$SqlAdapter.Fill($ds) | out-null | |
return [management.automation.languageprimitives]::GetEnumerator($ds.Tables[0]) | |
} | |
sq "SELECT * from information_schema.columns" | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment