I am having trouble with a PowerShell script calling a TSQL query result. I want the result of my SQL query to be assigned to the $Output variable as a single value, not a dataset. From my PowerShell script below the $Output variable returns…
$Output
Column1
--------
100
When I need the result to return a single value like the following…
$Output
100
Below is the PowerShell script I am using:
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Data Source= myserver;Initial
Catalog=mydatabase;Integrated Security=SSPI;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "select 100"
$SqlCmd.Connection = $SqlConnection
$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCmd
$Dataset = new-object System.Data.Dataset
write-output $DataAdapter.Fill($Dataset) | Out-Null
$Output = $DataSet.Tables
$Output
Any help would be greatly appreciated!