I am running a Powershell script that is able to execute SQL queries using the c# classes:
$MasterDatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
$MasterDatabaseConnection.ConnectionString = "<Connectionstring>"
$MasterDatabaseConnection.Open()
#Create & Run query
$MasterDatabaseCommand = New-Object System.Data.SqlClient.SqlCommand
$MasterDatabaseCommand.Connection = $MasterDatabaseConnection
$MasterDatabaseCommand.CommandTimeout = 1200;
$MasterDatabaseCommand.CommandText = "select top 1 * from TestTable"
$Results = $MasterDatabaseCommand.ExecuteNonQuery()
$Results
However, How can I get the function ExecuteNonQuery() to return the actual output of the row I am fetching? It only returns the success or not of the query.
I cannot solve this by using other powershell-modules or c# programs.