You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should $PSScriptRoot be added to foreach-object-Parallel? #15302
See #12240, which more generally proposes copying the caller's state to the runspaces of the parallel threads on an opt-in basis [update: but $PSScriptRoot would require special handling; see next comment].
Michael Klement (@mklement0)PSScriptRoot would need to be handled on it's own. It's the closest thing PowerShell has to a lexically scoped variable and is overwritten at the start of every new script based command.
e.g.
$PSScriptRoot='test'. { $PSScriptRoot }
# empty
-Parallel would need to recreate the scriptblock with something like this:
Activity
mklement0 commentedon Apr 25, 2021
See #12240, which more generally proposes copying the caller's state to the runspaces of the parallel threads on an opt-in basis [update: but
$PSScriptRootwould require special handling; see next comment].SeeminglyScience commentedon Apr 26, 2021
Michael Klement (@mklement0)
PSScriptRootwould need to be handled on it's own. It's the closest thing PowerShell has to a lexically scoped variable and is overwritten at the start of every new script based command.e.g.
-Parallelwould need to recreate the scriptblock with something like this:but then the challenge is that the
PowerShellAPI does not make it easy to directly invoke a scriptblock (#15004).(I know you already know that last bit, included for context)
PaulHigin commentedon Apr 26, 2021
This can be considered as part of the #12240 work.
PaulHigin commentedon Apr 26, 2021
Closing and merging as part of #12240.