{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2035","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2035/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2035/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2035/events","html_url":"https://github.com/PowerShell/PowerShell/issues/2035","id":172737066,"number":2035,"title":"Parameter binding problem with ValueFromRemainingArguments in PS functions","user":{"login":"dlwyatt","id":5107604,"avatar_url":"https://avatars.githubusercontent.com/u/5107604?v=3","gravatar_id":"","url":"https://api.github.com/users/dlwyatt","html_url":"https://github.com/dlwyatt","followers_url":"https://api.github.com/users/dlwyatt/followers","following_url":"https://api.github.com/users/dlwyatt/following{/other_user}","gists_url":"https://api.github.com/users/dlwyatt/gists{/gist_id}","starred_url":"https://api.github.com/users/dlwyatt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlwyatt/subscriptions","organizations_url":"https://api.github.com/users/dlwyatt/orgs","repos_url":"https://api.github.com/users/dlwyatt/repos","events_url":"https://api.github.com/users/dlwyatt/events{/privacy}","received_events_url":"https://api.github.com/users/dlwyatt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-08-23T15:51:55Z","updated_at":"2016-08-28T18:23:58Z","closed_at":null,"body":"Steps to reproduce\r\n------------------\r\n\r\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.\r\n\r\n```posh\r\n & {\r\n     param(\r\n         [string]\r\n         [Parameter(Position=0)]\r\n         $Root,\r\n\r\n         [string[]]\r\n         [Parameter(Position=1, ValueFromRemainingArguments)]\r\n         $Extra)\r\n     $Extra.Count;\r\n     for ($i = 0; $i -lt $Extra.Count; $i++)\r\n     {\r\n        \"${i}: $($Extra[$i])\"\r\n     }\r\n } root aa,bb\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\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:\r\n\r\n2\r\n0: aa\r\n1: bb\r\n\r\nActual behavior\r\n---------------\r\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:\r\n\r\n1\r\n0: aa bb\r\n\r\nAdditional information\r\n------------------\r\n\r\nTo demonstrate that the behavior of cmdlets is different, you can use this code:\r\n\r\n```posh\r\nAdd-Type -OutputAssembly $env:temp\\testBinding.dll -TypeDefinition @'\r\n    using System;\r\n    using System.Management.Automation;\r\n\r\n    [Cmdlet(\"Test\", \"Binding\")]\r\n    public class TestBindingCommand : PSCmdlet\r\n    {\r\n        [Parameter(Position = 0)]\r\n        public string Root { get; set; }\r\n\r\n        [Parameter(Position = 1, ValueFromRemainingArguments = true)]\r\n        public string[] Extra { get; set; }\r\n\r\n        protected override void ProcessRecord()\r\n        {\r\n            WriteObject(Extra.Length);\r\n            for (int i = 0; i < Extra.Length; i++)\r\n            {\r\n                WriteObject(String.Format(\"{0}: {1}\", i, Extra[i]));\r\n            }\r\n        }\r\n    }\r\n'@\r\n\r\nImport-Module $env:temp\\testBinding.dll\r\n\r\nTest-Binding root aa,bb\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n<!-- provide the output of $PSVersionTable -->\r\n\r\n```powershell\r\n> $PSVersionTable\r\nName                           Value\r\n----                           -----\r\nPSEdition                      Core\r\nPSVersion                      6.0.0-alpha\r\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}\r\nWSManStackVersion              3.0\r\nGitCommitId                    v6.0.0-alpha.9-107-g203ace04c09dbbc1ac00d6b497849cb69cc919fb-dirty\r\nPSRemotingProtocolVersion      2.3\r\nCLRVersion\r\nSerializationVersion           1.1.0.1\r\nBuildVersion                   3.0.0.0\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/242990519","html_url":"https://github.com/PowerShell/PowerShell/issues/2035#issuecomment-242990519","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2035","id":242990519,"user":{"login":"dlwyatt","id":5107604,"avatar_url":"https://avatars.githubusercontent.com/u/5107604?v=3","gravatar_id":"","url":"https://api.github.com/users/dlwyatt","html_url":"https://github.com/dlwyatt","followers_url":"https://api.github.com/users/dlwyatt/followers","following_url":"https://api.github.com/users/dlwyatt/following{/other_user}","gists_url":"https://api.github.com/users/dlwyatt/gists{/gist_id}","starred_url":"https://api.github.com/users/dlwyatt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlwyatt/subscriptions","organizations_url":"https://api.github.com/users/dlwyatt/orgs","repos_url":"https://api.github.com/users/dlwyatt/repos","events_url":"https://api.github.com/users/dlwyatt/events{/privacy}","received_events_url":"https://api.github.com/users/dlwyatt/received_events","type":"User","site_admin":false},"created_at":"2016-08-28T18:23:58Z","updated_at":"2016-08-28T18:23:58Z","body":"For that, you'd behave just like any other array parameter where you wanted to send in a single-element array (such as -ArgumentList when calling New-Object for constructors that take an array):  unary comma.\r\n\r\n`Do-Something ,Extra1,Extra2,Extra3`"}}
{"actor":{"display_login":"dlwyatt"}}