Title: Allow Measure-Object to accept ad-hoc script-block arguments in lieu of property names · Issue #6855 · PowerShell/PowerShell · GitHub
Open Graph Title: Allow Measure-Object to accept ad-hoc script-block arguments in lieu of property names · Issue #6855 · PowerShell/PowerShell
X Title: Allow Measure-Object to accept ad-hoc script-block arguments in lieu of property names · Issue #6855 · PowerShell/PowerShell
Description: 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 prop...
Open Graph Description: 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 e...
X Description: 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 there...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/6855
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Allow Measure-Object to accept ad-hoc script-block arguments in lieu of property names","articleBody":"\u003csup\u003eThis issue arose out of #6837.\u003c/sup\u003e\r\n\r\nMotivation:\r\n\r\n`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.:\r\n\r\n```powershell\r\n# Sort by only the numerical part of the input, via a script-block parameter argument.\r\nPS\u003e 'z1', 'a0', 'b10' | Sort-Object -Property { [int] $_.Substring(1) }\r\na0\r\nz1\r\nb10\r\n```\r\n\r\nSuggestion:\r\n\r\nIt would be handy if `Measure-Object` supported analogous use; e.g.:\r\n\r\n```powershell\r\n# Count the odd numbers in the input.\r\nPS\u003e 1, 2, 3 | Measure-Object -Sum -Property { $_ % 2 } # wishful thinking\r\n2\r\n```\r\n\r\nTo that end:\r\n\r\n* The `-Property` parameter's data type would have to change from`[string[]]` to `[object[]]`\r\n* 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.\r\n\r\n\r\nEnvironment data\r\n----------------\r\n\r\nWritten as of:\r\n\r\n```powershell\r\nPowerShell Core v6.0.2\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2018-05-11T13:56:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/6855/PowerShell/issues/6855"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7e2fbd98-a682-ff2b-e851-0ee72bf415e0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6B8:7B7FE:26FAA27:346A3EF:6A59B338 |
| html-safe-nonce | d9b1225a77b3ef85c6246b2a0d3944e86d5ebf97d7c74a3edd5f09c10d583f5e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkI4OjdCN0ZFOjI2RkFBMjc6MzQ2QTNFRjo2QTU5QjMzOCIsInZpc2l0b3JfaWQiOiI4NzM2MzQ4MzY2NzUyNTU5OTI4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 87f7d674d46437058da3a958def5aec59834c14fbc1475cea2b72a20a38c1d7a |
| hovercard-subject-tag | issue:322306558 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/6855/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fba2ba6ffe4c66a4d51780251d9a100b152d9cf6849d92be65fca3f6ae9a79e1/PowerShell/PowerShell/issues/6855 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fba2ba6ffe4c66a4d51780251d9a100b152d9cf6849d92be65fca3f6ae9a79e1/PowerShell/PowerShell/issues/6855 |
| og:image:alt | 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 e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | ba3976babb66479b1c943a8edc0777d96157da48fadc0161f9ddb219deee8353 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ab680789ae4a316cdaf0d5a292a1760140931cc4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width