-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add a -Recurse switch to Measure-Object to support input objects / properties that are collections themselves #7244
Copy link
Copy link
Closed
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues
Description
Currently, Measure-Object treats each input object / input object's property as a scalar; e.g.:
PS> ((1, 2), (3, 4) | Measure-Object).Count
2 # The input arrays each counted as *1* object - their elements weren't counted.
PS> ([pscustomobject] @{ prop = 1, 2 }, [pscustomobject] @{ prop = 3, 4 } |
Measure-Object -Property prop).Count
2 # The arrays stored in .prop each counted as *1* object - their elements weren't counted.Note that if you also specified a switch such as -Sum, the commands would break, because an attempt is made to interpret the array as a number, which fails: Measure-Object : Input object "System.Object[]" is not numeric.
It would be handy if a -Recurse switch would allow opting into recursing into array-valued input objects / properties:
PS> ((1, 2), (3, 4) | Measure-Object -Recurse).Count # WISHFUL THINKING
4 # The input arrays' elements were counted individually
PS> ([pscustomobject] @{ prop = 1, 2 }, [pscustomobject] @{ prop = 3, 4 } |
Measure-Object -Recurse -Property prop).Count # WISHFUL THINKING
4 # The elements of the arrays stored in .prop were counted individuallyEnvironment data
Written as of:
PowerShell Core v6.1.0-preview.3Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issuesgeneral cmdlet issues