Param
(
# Path to an MSI file
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$true,
Position=0,
ParameterSetName='Default')]
[ValidateNotNullOrEmpty()]
[String[]]$Path
)
I’ve just realised that it is sending it through when I added ValueFromRemainingArguments=$true. However It is now passing it through as a string rather than dealing with it in the begin,process,end block as individual strings like passing on the pipeline does
Aren’t necessarily the same; PowerShell uses a space to detect where one value stops and the next parameter value begins. Because you’re using positional parameters, you leave a lot up to the shell’s discretion. If you really want to test this, use:
That’ll tell you if the parameter is working as intended, since the @() array operator explicitly forces an array. If you really want to dig into the troubleshooting, use Trace-Command to view a parameterbinding dump of your command bring run with two array items - that’ll show you exactly what PowerShell is trying to do under the hood.
The comma seems to denote that something else is coming for the parameter so it doesn’t matter if you have a space after the comma or not, the next parameter follows a space without a preceding comma
The problem is that I was expecting the begin,process,end block to handle the variables in the array individually like it does if you were passing something through the pipeline. It doesn’t it passes a whole array through, so you have to process the array yourself.