Splatting From Top Level Function to a Series of Inner Function

suggest change

Passing 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents