Since -ArgumentList takes Object[] , I think it is received by caller as a string. One way is to:
function caller ($runthis) { $runthis = $executioncontext.InvokeCommand.NewScriptBlock($runthis) & $runthis }
Please note that something like this works:
function caller ($runthis) { $runthis | kill } $p= Get-Process -name notepad invoke-command -computer localhost -ScriptBlock ${function:caller} -ArgumentList $p
I think script blocks are handled differently, as this may be considered a security issue, just to run them.
source share