Alex Rivera | Logout

How do I Start a job of a function i just defined?

Asked 2011-08-23T13:53:15.847
32

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.

Edit
Report

1 Answer

3

The function needs to be inside the scriptblock:

Start-Job -ScriptBlock { function FOO { write-host "HEY" } ; FOO } | Wait-Job | Receive-Job
answered 2011-08-23T14:19:58.850

Your Answer