title: Passing objects to PowerShell functions
body: <p>I'm trying to pass a SQL adapter object to a PowerShell function but I'm getting this error:</p>
  <blockquote>
  <p>executeQueryAndFillTable : Cannot process argument transformation on
  parameter 'da'. Cannot convert the &quot;System.Object[]&quot; value of type
  &quot;System.Object[]&quot; to type &quot;System.Data.SqlClient.SqlDataAdapter&quot;.</p>
  </blockquote>
  <p>Here's the code</p>
  <pre><code>function sql_pull
  {
      # define Objects
      $xmlDoc = New-Object System.Xml.XmlDocument
      $sqlConnection = New-Object System.Data.SqlClient.SqlConnection
      $sqlCommand = New-Object System.Data.SqlClient.SqlCommand
      $sqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
      $connectionString = &quot;Password=$password;Persist Security Info=True;User ID=$userId;Data Source=$dataSource&quot;
      $counter = 0
  
      # database queries 
      $queries = @(
      &quot;Select * from sys.configurations for xml Raw ('Cretiria'), type, ROOT('sys.configurations'), ELEMENTS&quot;);
  
      $sqlConnection.ConnectionString = $connectionString
      $sqlCommand.Connection = $sqlConnection
  
      try {
          $sqlConnection.Open()
          
          foreach($q in $queries) 
          {
              $sqlCommand.CommandText = $q
              $sqlAdapter.SelectCommand = $sqlCommand.CommandText
              $sqlAdapter.SelectCommand.CommandTimeout = 300
  
              $res = executeQueryAndFillTable($sqlAdapter, $sqlCommand)              
          }
  
          $sqlConnection.Dispose()
          $sqlCommand.Dispose()
          $sqlAdapter.Dispose()
      } 
      catch
      {
          Throw
      }    
  }
  
  function executeQueryAndFillTable
  {
      param(
          [System.Data.SqlClient.SqlDataAdapter]$da,
          [System.Data.SqlClient.SqlCommand] $command
      )
  
      $dataTable = New-Object System.Data.DataTable
      $da.SelectCommand = $command
      $da.Fill($dataTable)
      #check
      $data = $dataTable.Rows[0][0]
      return $data
  }
  </code></pre>