This following error occurs when a variable, e.g. varSuffixed, passed as an argument to a function is prefixed with the other variable name, e.g. var, which also passed to the function but is not specified as an argument within the function: Cannot bind parameter because parameter 'varSuffixed' is specified more than once.
The error does not occur if both arguments are specified or if the prefix variable is the specified argument in the function. The error also occurs when not splatting the variables as well.
An example is below:
$args = @{
"var"="blah";
"varSuffixed"="blah2";
}
function Do-WorkingFunction($var, $varSuffixed){
Write-Host($var)
Write-Host($varSuffixed);
}
function Do-BrokenFunction($varSuffixed){
Write-Host($varSuffixed);
}
Do-WorkingFunction @args
Do-BrokenFunction @args
When trying to access the variable varSuffixed in Do-BrokenFunction, the following error occurs: Cannot bind parameter because parameter 'varSuffixed' is specified more than once.
Can anybody explain why this is?
This has been tested with PowerShell versions 2 and 5.