title: Powershell Select-Object vs ForEach on Select-String results
body: <p>Let's say I have the results of a call to Select-String in a variable $mat, parsing a regular expression from file contents:</p>
  <pre><code>$mat = cat errors.txt | Select-String &quot;'(?&lt;code&gt;\w+)'.+ID (?&lt;id&gt;[^:]+)&quot; 
  </code></pre>
  <p>According to the output of <code>$mat | Get-Member</code> the result contains a Matches property of type <code>Match[]</code>.</p>
  <p>When I execute the following I get all the matches of my regular expression output:</p>
  <pre><code>PS &gt; $mat | Select-Object -Property Matches
  
  Matches                                                                                                                                                                              
  -------                                                                                                                                                                              
  {'ACCFWD', ID 16}                                                                                                                                                                    
  {'EQASIAN', ID 448}                   
      
  </code></pre>
  <p>Why doesn't this next block of code using foreach to select the Matches have the same output:</p>
  <pre><code>    PS &gt; $mat | ForEach { $_.Matches } 
  
  
  Groups   : {'ACCFWD', ID 16, ACCFWD, 16}
  Success  : True
  Captures : {'ACCFWD', ID 16}
  Index    : 20
  Length   : 15
  Value    : 'ACCFWD', ID 16
  
  Groups   : {'EQASIAN', ID 448, EQASIAN, 448}
  Success  : True
  Captures : {'EQASIAN', ID 448}
  Index    : 20
  Length   : 17
  Value    : 'EQASIAN', ID 448
  </code></pre>