In Powershell with the function Start-Job you can call functions if you initialize them beforehand.
$export_functions =
{
Function Log($message) {Write-Host $message}
Function MyFunction($message) {Log($message)}
}
$param1="Hello stack overflow!"
Start-Job -ScriptBlock {MyFunction $using:param1} -InitializationScript $export_functions -ArgumentList @($param1) | Wait-Job | Receive-Job
Would it be possible to use a 'global' function inside the script block as well? So something like:
Function Log($message) {Write-Host $message}
$export_functions =
{
Function Log($message) {$Function:Log($message)}
Function MyFunction($message) {Log($message)}
}
$param1="Hello stack overflow!"
Start-Job -ScriptBlock {MyFunction $using:param1} -InitializationScript $export_functions -ArgumentList @($param1) | Wait-Job | Receive-Job
Or is that not intended after all?