Last active
June 30, 2018 15:37
-
-
Save mrhockeymonkey/6579466589ebae7a0ecad83347ee725e to your computer and use it in GitHub Desktop.
Invoke SQL queries the old way
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
# This is the old way I used to invoke sql queries. | |
# A better way now would be to use the SqlServer module and Invoke-SqlCommand | |
$tsqlQuery = @" | |
Select AccountName | |
From SUSDB.dbo.tbDownstreamServerTarget | |
"@ | |
Try { | |
$conn.Open() | |
} | |
Catch { | |
$PSCmdlt.ThrowTerminatingError($_) | |
} | |
$command = $conn.CreateCommand() | |
$command.CommandText = $tsqlQuery | |
$table = new-object System.Data.DataTable | |
$data = $command.ExecuteReader() | |
$table.load($data) | |
$conn.Close() | |
$conn.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment