Invoke SQL Queries

Running SQL queries from powershell can be extremely powerfull. However some implementation I have see often result with off object types such as DBNull. This is my method that seems to work quite nicely for me.

$tsqlQuery = @"
Select AccountName
From SUSDB.dbo.tbDownstreamServerTarget
Try {
Catch  {

$command = $conn.CreateCommand()
$command.CommandText = $tsqlQuery
$table = new-object System.Data.DataTable
$data = $command.ExecuteReader()


Leave a Reply

Your email address will not be published. Required fields are marked *