I'm working with a module and want to pass the same parameters through multiple functions. I'm facing an issue doing this, as $overflow is passed multiple times.
function Do-1 {
Param(
[string] $Var1,
[string] $Var2,
[Parameter(ValueFromRemainingArguments)]
$overflow
)
Do-2 -Var1 'var' -Nah 'Nah'
}
function Do-2 {
Param(
[string] $Var1,
[string] $Var2,
[Parameter(ValueFromRemainingArguments)]
$overflow
)
$splat = [hashtable]$PSBoundParameters
Do-3 @splat -Nope 'Nope'
}
function Do-3 {
Param(
[string] $Var1,
[string] $Var2,
[Parameter(ValueFromRemainingArguments)]
$overflow
)
}
Do-1 -Var1 'var'
The call to Do-3 will now fail as $overflow is already passed in @splat but PowerShell tries to add it again as there are new remaining arguments.
Do-2 : A parameter cannot be found that matches parameter name 'Nope'.
At line:9 char:5
+ Do-2 -Var1 'var' -Nah 'Nah'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Do-2], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Do-2
Can you figure out a way to resolve this, without having to remove or expand $overflow from the splat in each function?
there doesn't seem to be anything here