This issue arose out of #6837.
Motivation:
Sort-Object's -Property not only supports property names (the typical case), but also script blocks that are evaluated for each input object and thereby enable sorting criteria derived from properties, which is a powerful feature (also found, in essence, in Select-Object); e.g.:
# Sort by only the numerical part of the input, via a script-block parameter argument.
PS> 'z1', 'a0', 'b10' | Sort-Object -Property { [int] $_.Substring(1) }
a0
z1
b10
Suggestion:
It would be handy if Measure-Object supported analogous use; e.g.:
# Count the odd numbers in the input.
PS> 1, 2, 3 | Measure-Object -Sum -Property { $_ % 2 } # wishful thinking
2
To that end:
- The
-Property parameter's data type would have to change from[string[]] to [object[]]
- In the event of a script block getting passed, it would have to be evaluated for each input object and used in lieu of a simple property access on the input object.
Environment data
Written as of:
This issue arose out of #6837.
Motivation:
Sort-Object's-Propertynot only supports property names (the typical case), but also script blocks that are evaluated for each input object and thereby enable sorting criteria derived from properties, which is a powerful feature (also found, in essence, inSelect-Object); e.g.:Suggestion:
It would be handy if
Measure-Objectsupported analogous use; e.g.:To that end:
-Propertyparameter's data type would have to change from[string[]]to[object[]]Environment data
Written as of:
PowerShell Core v6.0.2