Title: Parameter binding problem with ValueFromRemainingArguments in PS functions · Issue #2035 · PowerShell/PowerShell · GitHub
Open Graph Title: Parameter binding problem with ValueFromRemainingArguments in PS functions · Issue #2035 · PowerShell/PowerShell
X Title: Parameter binding problem with ValueFromRemainingArguments in PS functions · Issue #2035 · PowerShell/PowerShell
Description: Steps to reproduce Define a PowerShell function with an array parameter using the ValueFromRemainingArguments property of the Parameter attribute. Instead of sending multiple arguments, send that parameter a single array argument. & { pa...
Open Graph Description: Steps to reproduce Define a PowerShell function with an array parameter using the ValueFromRemainingArguments property of the Parameter attribute. Instead of sending multiple arguments, send that p...
X Description: Steps to reproduce Define a PowerShell function with an array parameter using the ValueFromRemainingArguments property of the Parameter attribute. Instead of sending multiple arguments, send that p...
Mail addresses
notifications@github.com
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/2035
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Parameter binding problem with ValueFromRemainingArguments in PS functions","articleBody":"## Steps to reproduce\n\nDefine a PowerShell function with an array parameter using the ValueFromRemainingArguments property of the Parameter attribute. Instead of sending multiple arguments, send that parameter a single array argument.\n\n``` posh\n & {\n param(\n [string]\n [Parameter(Position=0)]\n $Root,\n\n [string[]]\n [Parameter(Position=1, ValueFromRemainingArguments)]\n $Extra)\n $Extra.Count;\n for ($i = 0; $i -lt $Extra.Count; $i++)\n {\n \"${i}: $($Extra[$i])\"\n }\n } root aa,bb\n```\n## Expected behavior\n\nThe array should be bound to the parameter just as you sent it, the same way it works for cmdlets. (The \"ValueFromRemainingArguments\" behavior isn't used, in this case, it should just bind like any other array parameter type.) The output of the above script block should be:\n\n2\n0: aa\n1: bb\n## Actual behavior\n\nPowerShell appears to be performing type conversion on the argument to treat the array as a single element of the parameter's array, instead of checking first to see if more arguments will be bound as \"remaining arguments\" first. The output of the above script block is currently:\n\n1\n0: aa bb\n## Additional information\n\nTo demonstrate that the behavior of cmdlets is different, you can use this code:\n\n``` posh\nAdd-Type -OutputAssembly $env:temp\\testBinding.dll -TypeDefinition @'\n using System;\n using System.Management.Automation;\n\n [Cmdlet(\"Test\", \"Binding\")]\n public class TestBindingCommand : PSCmdlet\n {\n [Parameter(Position = 0)]\n public string Root { get; set; }\n\n [Parameter(Position = 1, ValueFromRemainingArguments = true)]\n public string[] Extra { get; set; }\n\n protected override void ProcessRecord()\n {\n WriteObject(Extra.Length);\n for (int i = 0; i \u003c Extra.Length; i++)\n {\n WriteObject(String.Format(\"{0}: {1}\", i, Extra[i]));\n }\n }\n }\n'@\n\nImport-Module $env:temp\\testBinding.dll\n\nTest-Binding root aa,bb\n```\n## Environment data\n\n\u003c!-- provide the output of $PSVersionTable -->\n\n``` powershell\n> $PSVersionTable\nName Value\n---- -----\nPSEdition Core\nPSVersion 6.0.0-alpha\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\nWSManStackVersion 3.0\nGitCommitId v6.0.0-alpha.9-107-g203ace04c09dbbc1ac00d6b497849cb69cc919fb-dirty\nPSRemotingProtocolVersion 2.3\nCLRVersion\nSerializationVersion 1.1.0.1\nBuildVersion 3.0.0.0\n```\n","author":{"url":"https://github.com/dlwyatt","@type":"Person","name":"dlwyatt"},"datePublished":"2016-08-23T15:51:55Z","url":"https://github.com/PowerShell/PowerShell/issues/2035"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:2b15c88a-95b8-2e53-8389-ac695adfe7fc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3C8:2A3251:10ED28:180E3F:6AFD5DAE |
| html-safe-nonce | 33f0afd464f5fc1f5e689404df6709f68fa926a36b7c5e8e65d9e29d05594aab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0M4OjJBMzI1MToxMEVEMjg6MTgwRTNGOjZBRkQ1REFFIiwidmlzaXRvcl9pZCI6IjE0NTcwNzg2MjYzMDk0NjM0NzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 37d48e05c8d600c3be74423b504c27035cfea0d2ad2e0bb0d24d30cd2d91313c |
| hovercard-subject-tag | issue:172737066 |
| 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/2035/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e18b677c9136ca2f5a324921a6d2e610646aa511956865c6d9b3002dce499d3d/PowerShell/PowerShell/issues/2035 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e18b677c9136ca2f5a324921a6d2e610646aa511956865c6d9b3002dce499d3d/PowerShell/PowerShell/issues/2035 |
| og:image:alt | Steps to reproduce Define a PowerShell function with an array parameter using the ValueFromRemainingArguments property of the Parameter attribute. Instead of sending multiple arguments, send that p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dlwyatt |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width