PSThreadJob icon indicating copy to clipboard operation
PSThreadJob copied to clipboard

-InitializationScript does not support $using: variable references

Open mklement0 opened this issue 5 years ago • 1 comments

To next best thing to having a -WorkingDirectory parameter (hopefully soon, see #44) is to try something like the following:

Start-ThreadJob -InitializationScript { Set-Location $using:PWD } { $PWD } |
  Receive-Job -Wait -AutoRemoveJo

However, this currently fails:

A Using variable cannot be retrieved. 
A Using variable can be used only with Invoke-Command, Start-Job, or InlineScript
in the script workflow. 
When it is used with Invoke-Command, the Using variable is valid only if the script block is invoked on a remote computer.

This appears to be the same bug as in PowerShell itself (not sure how code is shared): https://github.com/PowerShell/PowerShell/issues/4530

As an aside re the error message:

  • Since Start-ThreadJob now ships with PowerShell, the error message should probably mention it as well.
  • The reference to workflows should probably be removed.

mklement0 avatar Sep 26 '19 18:09 mklement0

@PaulHigin This is rather important IMHO, any timeframe on fixing this? Also which is the correct repo to create issues now. This one or the that?

kborowinski avatar Mar 11 '23 16:03 kborowinski