1

We want to execute two PowerShell functions in parallel. We found that Start-Job is looking good; however, we don't know all the parameters the function needs, and therefore we cannot pass them all via the -ArgumentList parameter.

How to call Start-Job (or a viable alternative?) in such a way that the inner function has the exact same "variable environment" as the caller?

(edit: also all functions/modules should be present as well)

4
  • It sounds like the $using: variable scope might be what you want here. See this previous SO post: stackoverflow.com/questions/24996816/… Commented Feb 21, 2018 at 15:38
  • however, we don't know all the parameters the function needs, But the environment does at runtime? So why not obtain the parameters from there then? I hope you don't hope to manipulate the same variable via multiple jobs. Commented Feb 21, 2018 at 15:43
  • Nope, variables would be used read-only. How to obtain the parameters from there in a transparent way? The called function should still be working when not called in a Start-Job-parallel-scenario. Commented Feb 21, 2018 at 15:47
  • 3
    IMO it sounds like you should rewrite the function(s) to take the appropriate input data as parameters rather than rely on the execution context Commented Feb 21, 2018 at 15:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.