How do I Start a job of a function i just defined?
function FOO { write-host "HEY" }
Start-Job -ScriptBlock { FOO } |
Receive-Job -Wait -AutoRemoveJob
Result:
Receive-Job: The term 'FOO' is not recognized as the name of cmdlet,
function ,script file or operable program.
What do I do?
Thanks.
As @Shay points out,
FOOneeds to be defined for the job. Another way to do this is to use the-InitializationScriptparameter to prepare the session.For your example:
This can be useful if you want to use the same functions for different jobs.