Currently, script blocks passed to Start-ThreadJob default to the process-wide current directory, as reflected in [Environment]::CurrentDirectory.
However, this is problematic, because that directory has no guaranteed or obvious relationship with the caller's current location.
Therefore, defaulting to the caller's current location instead is the most useful and intuitive behavior.
While technically a breaking change, my sense is that it falls into Bucket 3: Unlikely Grey Area, given that the effective $PWD is virtually unpredictable by the user:
$PWD is whatever PowerShell's startup directory was - irrespective of a -WorkingDirectory argument passed to the CLI - or whatever in-session code that changed the process-wide current directory last set it to.
That is, the above made / (or, on Windows, C:\) the $PWD for thread jobs, just because the pwsh instance was invoked while that directory happened to have been the process-wide working directory - even though the session's $PWD is $HOME.
Following up from the discussion in https://github.com/PowerShell/PowerShell/issues/10537:
Currently, script blocks passed to
Start-ThreadJob
default to the process-wide current directory, as reflected in[Environment]::CurrentDirectory
.However, this is problematic, because that directory has no guaranteed or obvious relationship with the caller's current location.
Therefore, defaulting to the caller's current location instead is the most useful and intuitive behavior.
While technically a breaking change, my sense is that it falls into Bucket 3: Unlikely Grey Area, given that the effective
$PWD
is virtually unpredictable by the user:$PWD
is whatever PowerShell's startup directory was - irrespective of a-WorkingDirectory
argument passed to the CLI - or whatever in-session code that changed the process-wide current directory last set it to.A simple example:
That is, the above made
/
(or, on Windows,C:\
) the$PWD
for thread jobs, just because thepwsh
instance was invoked while that directory happened to have been the process-wide working directory - even though the session's$PWD
is$HOME
.