title: How to use the "-Property" parameter for PowerShell's "Measure-Object" cmdlet?
body: <p>Why does</p>
  
  <pre><code>$a = GPS AcroRd32 | Measure
  $a.Count
  </code></pre>
  
  <p>work, when</p>
  
  <pre><code>GPS AcroRd32 | Measure -Property Count
  </code></pre>
  
  <p>doesn't?</p>
  
  <p>The first example returns a value of <code>2</code>, which is what I want, an integer.</p>
  
  <p>The second example returns this:</p>
  
  <pre><code>Measure-Object : Property "Count" cannot be found in any object(s) input.
  At line:1 char:23
  + GPS AcroRd32 | Measure &lt;&lt;&lt;&lt;  -Property Count
      + CategoryInfo          : InvalidArgument: (:) [Measure-Object], PSArgumentException
      + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
  </code></pre>
  
  <p><br /></p>
  
  <hr />
  
  <p><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2008/04/28/how-can-i-use-windows-powershell-to-determine-the-number-of-lines-in-a-text-file.aspx" rel="nofollow noreferrer">This Scripting Guy entry</a> is where I learned how to use the "Count" Property in the first code sample.</p>
  
  <p>The second code sample is really confusing. In <a href="http://technet.microsoft.com/en-us/library/ee176900.aspx" rel="nofollow noreferrer">this Script Center reference</a>, the following statement works:</p>
  
  <pre><code>Import-Csv c:\scripts\test.txt | Measure-Object score -ave -max -min
  </code></pre>
  
  <p>It still works even if it's re-written like so:</p>
  
  <pre><code>Import-Csv c:\scripts\test.txt | Measure-Object -ave -max -min -property score
  </code></pre>
  
  <p>I don't have too many problems with accepting this until I consider the <a href="http://technet.microsoft.com/en-us/library/dd315251.aspx" rel="nofollow noreferrer">Measure-Object help page</a>. The parameter definition for <code>-Property &lt;string[]&gt;</code> states:</p>
  
  <blockquote>
    <p>The default is the Count (Length) property of the object.</p>
  </blockquote>
  
  <p>If <code>Count</code> is the default, then shouldn't an explicit pass of <code>Count</code> work?</p>
  
  <pre><code>GPS AcroRd32 | Measure -Property Count # Fails
  </code></pre>
  
  <p>The following provides me the information I need, except it doesn't provide me with an integer to perform operations on, as you'll see:</p>
  
  <pre><code>PS C:\Users\Me&gt; $a = GPS AcroRd32 | Measure
  PS C:\Users\Me&gt; $a
  
  Count    : 2
  Average  :
  Sum      :
  Maximum  :
  Minimum  :
  Property :
  
  PS C:\Users\Me&gt; $a -is [int]
  False
  </code></pre>
  
  <p><br /></p>
  
  <hr />
  
  <p>So, why does Dot Notation (<code>$a.count</code>) work, but not an explicitly written statement (<code>GPS | Measure -Property Count</code>)?</p>
  
  <p>If I'm supposed to use Dot Notation, then I will, but I'd like to take this opportunity to learn more about <strong>how</strong> and <strong>*why</strong> PowerShell works this way, rather than just building a perfunctory understanding of PowerShell's syntax. To put it another way, I want to avoid turning into a <a href="https://softwareengineering.stackexchange.com/questions/60949/am-i-a-code-monkey/60986#60986">Cargo Cult Programmer</a>/ <a href="https://softwareengineering.stackexchange.com/questions/60949/am-i-a-code-monkey/60951#60951">Code Monkey</a>.</p>