Setting the ValueFromRemainingArguments property allows a parameter to consume all of the other arguments supplied for a command. This can be used to make an advanced function act in a similar manner to a basic function.
For example, this basic function will fill the Parameter1 parameter with the first argument, and will ignore all others. The extra values are added to the $args automatic variable and are listed in the UnboundArguments property of the $MyInvocation automatic variable:
function Test-BasicBinding {
param (
$Parameter1
)
$MyInvocation.UnboundArguments
}
Calling the function with non-existent parameters will not raise an error. The additional values will be added to the UnboundArguments array (and the $args variable):
PS> Test-BasicBinding -Parameter1 value1 -Parameter2 value2
-Parameter2
Value2
Without a declared parameter in the param block, Parameter2 is just another value, it is not parsed as the name of a parameter. The ValueFromRemainingArguments property can be used to make an advanced function behave in much the same way as the preceding basic function:
function Test-AdvancedBinding {
[CmdletBinding()]
param (
$Parameter1,
[Parameter(ValueFromRemainingArguments)]
$OtherArguments
)
$OtherArguments
}
If the $OtherArguments parameter is not for the normal use of the function, the DontShow property might be added to make it less obvious and intrusive.