Silentbob
Silentbob

Reputation: 3065

Powershell - return a result from a stored procedure

I have a stored procedure in SQL Server 2012 and when it is ran it returns one row with 3 columns.

SP Result

In powershell I can return the data into a data table.

$sqlConnection.Open()
$sqlCommand = New-Object System.Data.SqlClient.SqlCommand
$sqlCommand.Connection = $sqlConnection
$sqlcommand.commandtext = "GetPlantLoadFactor"
$sqlCommand.CommandType = [System.Data.CommandType]::StoredProcedure
$result = $sqlCommand.executereader()
$table = new-object “System.Data.DataTable”
$table.Load($result)
$PLF = $table
$sqlConnection.close() 

$PLF

All I want is the Value field of 65.89. Is there a better way to do this and how do I just return the value of 65.89 into the variable $PLF?

Upvotes: 1

Views: 2312

Answers (1)

Kannan Kandasamy
Kannan Kandasamy

Reputation: 13959

You can try using rows

$table.Rows[0].Value

Upvotes: 1

Related Questions