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)

Clijsters
  • 4,031
  • 1
  • 27
  • 37
D.R.
  • 20,268
  • 21
  • 102
  • 205
  • It sounds like the $using: variable scope might be what you want here. See this previous SO post: https://stackoverflow.com/questions/24996816/powershell-remoting-using-variable-scope – trebleCode Feb 21 '18 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. – Clijsters Feb 21 '18 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. – D.R. Feb 21 '18 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 – Mathias R. Jessen Feb 21 '18 at 15:58

0 Answers0