title: PowerShell function not accepting array of objects
body: <p>In PowerShell, I have an array of objects that I need to pass to a function.  The function is to then loop through all of the objects in the array, but it seems that it is not accepting the parameter value correctly.</p>
  
  <p>Take the following example, where I pass an array containing two objects.  I would expect the count of the array to be 2 both before the function and within the function, but as soon as it hits the function the count is 1, and my input is not as expected; only the last object is discovered.</p>
  
  <p>Am I missing something here, or is this a bug in PowerShell?</p>
  
  <h1>Example code</h1>
  
  <pre><code>### I've also tries '[object]', '[array]' and '[array[]]' as the type for '$testArr'.
  function Test-PassArrayOfObjects
  {
      param(
          [parameter(Mandatory,ValueFromPipeline)]
          [object[]]$testArr
      )
      Write-Host "In function count: $($testArr.Count)"
      $testArr | ForEach-Object { $_ }
  }
  
  $test1 = New-Object –TypeName PSObject
  $test1 | Add-Member -MemberType NoteProperty -Name Test1 -Value Value1
  $test2 = New-Object –TypeName PSObject
  $test2 | Add-Member -MemberType NoteProperty -Name Test2 -Value Value2
  $testArr = @($test1, $test2)
  
  $testArr.GetType() | Format-Table
  Write-Host "Before function count: $($testArr.Count)"
  $testArr | Test-PassArrayOfObjects
  </code></pre>
  
  <h1>Output from example code</h1>
  
  <pre><code>IsPublic IsSerial Name     BaseType                                                                                                                                                                                              
  -------- -------- ----     --------                                                                                                                                                                                              
  True     True     Object[] System.Array                                                                                                                                                                                          
  
  
  Before function count: 2
  In function count: 1
  
  Test2 
  ----- 
  Value2
  </code></pre>
  
  <h1>Working fix</h1>
  
  <p>Based on the answer below, I have this working example, which I've been able to apply to my real life scenario.</p>
  
  <pre><code>function Test-PassArrayOfObjects
  {
      param(
          [parameter(Mandatory,ValueFromPipeline)]
          [object]$testArr
      )
      Process {
          Write-Host "In function count: $($testArr.Count)"
          $testArr
      }
  }
  
  $test1 = New-Object –TypeName PSObject
  $test1 | Add-Member -MemberType NoteProperty -Name Test1 -Value Value1
  $test1 | Add-Member -MemberType NoteProperty -Name Test2 -Value Value2
  $test2 = New-Object –TypeName PSObject
  $test2 | Add-Member -MemberType NoteProperty -Name Test1 -Value Value1
  $test2 | Add-Member -MemberType NoteProperty -Name Test2 -Value Value2
  $testArr = @($test1, $test2)
  
  $testArr.GetType() | Format-Table
  Write-Host "Before function count: $($testArr.Count)"
  $testArr | ForEach-Object { $_ | Test-PassArrayOfObjects }
  </code></pre>