Skip to content

$PSScriptRoot is not populated for scripts run in a ThreadJob #64

Description

@jazzdelightsme

The problem is pretty straightforward: I have a script that uses $PSScriptRoot, but when I ran the script in a ThreadJob, it malfunctioned, because $PSScriptRoot evaluated to an empty string.

Repro steps:

echo 'Write-Host "PSScriptRoot is: $PSScriptRoot"' > ReproThreadJobHasNoScriptRoot.ps1
start-threadjob -FilePath .\ReproThreadJobHasNoScriptRoot.ps1 | Receive-Job -Wait

Expected result:

PSScriptRoot is: <it should print out the current directory>

Actual result:

PSScriptRoot is:

Environment

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.7
PSEdition                      Core
GitCommitId                    7.1.0-preview.7
OS                             Microsoft Windows 10.0.20222
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions