I have this powershell script:
function Func1 ($val) { Write-Host "$val is processed by Func1"; } function Func2($val) { Invoke-Command -ScriptBlock ` ${function:Func1} -ArgumentList "$val is processed by Func2 and"; } function Func3($val) { $function:Func2.Invoke("$val is processed by Func3 and"); } Func3 "Value";
This works - it outputs the value handled by Func3 and handled by Func2 and handled by Func1 - but I am confused in two things:
What does the code $ {function: function-name} mean (that is, a dollar sign followed by an opening brace, followed by a function , followed by a colon, followed by the name of the function, followed by a closing brace) Func2 mean? I see that it calls Func1, but I donβt understand why it works.
What does $ function: function-name.Invoke code mean in Func3? I feel like it uses the functionality of the script block, as the Invoke method is called, but it is not clear to me how $ function.function-name is a script block.
source share