title: Powershell run stored procedure returns rows aswell as the input parameters
body: <p>I have a stored procedure which takes a date as a paramter and returns rows, in the return from the function in powershell an object array is returned containing the parameters and the rows. </p>
  
  <p>I know I can get around this by referencing the rows and working with them but I want to know why it returns the parameter. Can anyone shed some light please?</p>
  
  <pre><code>function Invoke-SQL($dataSource, $database, $sqlCommand, $tradeDate) {
  
      $result = New-Object System.Data.DataTable     
  
      $connectionString = "Data Source=$dataSource; Integrated Security=SSPI; Initial Catalog=$database"
      $connection = new-object system.data.SqlClient.SQLConnection($connectionString)
  
      $command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
      $command.CommandType = [System.Data.CommandType]::StoredProcedure
  
      $parameter = New-Object System.Data.SqlClient.SqlParameter ("@TradeDateParam", $tradeDate)
      $command.Parameters.Add($parameter);  
  
      $adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
  
      $connection.Open()   
      $adapter.Fill($result) | Out-Null
      $connection.Close()
  
      return $result
  }
  
  $resultsDataTable = New-Object system.Data.DataTable 
  $resultsDataTable = Invoke-SQL "server" "db" "sproc" "dateparam"
  
  
  
  ALTER PROCEDURE [dbo].[spCheckTradeActivityBetweenTradeDates]   
      @TradeDateParam date = null
  AS
  
  DECLARE @TradeDate date = @TradeDateParam;
  
  SELECT 'HEllO' AS hello
  return 0
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/XB7EZ.png" rel="nofollow noreferrer">Image of returned object array</a></p>