Created
December 13, 2019 12:33
-
-
Save omersiar/01b45ce73869ca3f718515083209fb42 to your computer and use it in GitHub Desktop.
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 Invoke-SQL { | |
param( | |
[string] $dataSource = "AIDCSVSWSQL01", | |
[string] $database = "SolarWindsOrion", | |
[string] $sqlCommand = $(throw "Please specify a query.") | |
) | |
$connectionString = "Data Source=$dataSource; " + | |
"Integrated Security=SSPI; " + | |
"Initial Catalog=$database" | |
$connection = new-object system.data.SqlClient.SQLConnection($connectionString) | |
$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection) | |
$connection.Open() | |
$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command | |
$dataset = New-Object System.Data.DataSet | |
$adapter.Fill($dataSet) | Out-Null | |
$connection.Close() | |
return $dataSet.Tables | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment