Splatting From Top Level Function to a Series of Inner Function
suggest changePassing values down the call stack is cumbersome without splatting. @PSBoundParameters passes the caller's bound parameters to the next function. A simple function ignores keys it does not declare, so Inner-Method receives $Second and ignores $First.
Function Outer-Method
{
Param
(
[string]
$First,
[string]
$Second
)
Write-Host ($First) -NoNewline
Inner-Method @PSBoundParameters
}
Function Inner-Method
{
Param
(
[string]
$Second
)
Write-Host (" {0}!" -f $Second)
}
$parameters = @{
First = "Hello"
Second = "World"
}
Outer-Method @parameters
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents