Why
$a = GPS AcroRd32 | Measure $a.Count
work when
GPS AcroRd32 | Measure -Property Count
not
The first example returns the value 2
that I want, an integer.
The second example returns this:
Measure-Object : Property "Count" cannot be found in any object(s) input. At line:1 char:23 + GPS AcroRd32 | Measure <<<< -Property Count + CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
This script - style entry is where I found out how to use the "Count" property in the first code sample.
The second code example is really confusing. The following statement works in this Script Center link :
Import-Csv c:\scripts\test.txt | Measure-Object score -ave -max -min
It still works, even if it is rewritten like this:
Import-Csv c:\scripts\test.txt | Measure-Object -ave -max -min -property score
I don't have much trouble accepting this until I review the Measure-Object's Help page . The parameter definition for -Property <string[]>
states:
By default, the Count (Length) property of the object is used.
If Count
is the default, then the explicit Count
count should not work
GPS AcroRd32 | Measure -Property Count
The following is the information I need, except that it does not provide me with an integer to perform operations, as you will see:
PS C:\Users\Me> $a = GPS AcroRd32 | Measure PS C:\Users\Me> $a Count : 2 Average : Sum : Maximum : Minimum : Property : PS C:\Users\Me> $a -is [int] False
So, why does Dot Notation ( $a.count
) work, but not an explicitly written statement ( GPS | Measure -Property Count
)?
If I have to use Dot Notation, then I will, but I would like to take this opportunity to learn more about how and * why PowerShell works this way, and not just build a superficial understanding of PowerShell syntax. In other words, I want not to turn into a Handicraft Programmer / Code Monkey .