I am Trying to Get the Results of a SQL Stored procedure that I am feeding multiple databases to restore. I have a function that Opens up the Connection with SQL as I'm going to be passing several databases to a single query. My problem is understanding how to get the results from the Stored procedure and being able to get values from those results.function SQLRestoreDatabase {
Param ($query, $connection)
$sqlCommand = new-object System.Data.SqlClient.SqlCommand
$sqlCommand.Connection= $connection
$sqlCommand.CommandText= $query
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $sqlCommand
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0]
}$sqlConnection = new-object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "server=" + $SQLServer + ";integrated security=true;database=" + $SQLDatabase
$SQLQuery = "exec dbo.restoredb"
SQLRestoreDatabase $SQLQuery $sqlConnectionThese are the results that are returned every time I run the query.
- I would like to be able to pull the value out of Col3. is there any way to do this or possibly a better way to run this SQL Stored Procedure to get the results that I am looking for?
- Is there a way to make it so the results are not Output but I can still use them.
- Also if there is a better way to format the output as Format-Table doesn't seem to do anything
Col1 Col2 Col3 DateTime
--------- ---------- ------------ -------------------
0 0 1 8/29/2009 2:36:22 AM