Skip to content

Start-Job fails on PowerShell 7.2.0 when installed as a .NET global tool #16537

@reduckted

Description

@reduckted

Prerequisites

Steps to reproduce

Use this script:

Set-StrictMode -Version 3.0
$ErrorActionPreference = "Stop"

$job = Start-Job -ScriptBlock { Write-Host "I am a job." }
Wait-Job -Job $job | Out-Null
Receive-Job -Job $job

✔️ When using PowerShell 7.1.5 as a .NET global tool, the script runs successfully.
✔ When using PowerShell 7.2.0 from the MSI installer, the script runs successfully.
❌ When using PowerShell 7.2.0 as a .NET global tool, the script fails.

The error is:

The pwsh executable cannot be found at
     | "C:\Users\<username>\.dotnet\tools\.store\powershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe"

It's true that the file does not exist:

> get-childitem *pwsh*

    Directory: C:\Users\<username>\.dotnet\tools\.store\powershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           2/11/2021    09:04         100424 pwsh.deps.json
-a---           2/11/2021    09:10         143736 pwsh.dll
-a---           2/11/2021    09:04            583 pwsh.runtimeconfig.json

Using PowerShell 7.1.5, that directory also contains pwsh.exe. That file is missing in PowerShell 7.2.0.

Expected behavior

> pwsh .\test.ps1
I am a job

Actual behavior

> pwsh .\test.ps1
Start-Job: D:\test.ps1:4
Line |
   4 |  $job = Start-Job -ScriptBlock { Write-Host "I am a job." }
     |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The pwsh executable cannot be found at
     | "C:\Users\<username>\.dotnet\tools\.store\powershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe". Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being hosted in other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.

Error details

Type           : System.Management.Automation.CmdletInvocationException
ErrorRecord    :
    Exception             :
        Type        : System.Management.Automation.PSNotSupportedException
        ErrorRecord :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : The pwsh executable cannot be found at "C:\Users\<username>\.dotnet\tools\.sto
re\powershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe".
                          Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being
hosted in other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.
                HResult : -2146233087
            CategoryInfo          : NotImplemented: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : NotSupported
        TargetSite  :
            Name          : ThrowTerminatingError
            DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation,
Version=7.2.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message     : The pwsh executable cannot be found at "C:\Users\<username>\.dotnet\tools\.store\p
owershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe".
                      Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being hosted
in other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.
        Source      : System.Management.Automation
        HResult     : -2146233067
        StackTrace  :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
    TargetObject          :
C:\Users\<username>\.dotnet\tools\.store\powershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe
    CategoryInfo          : NotInstalled: (C:\Users\david.bieg….0\any\win\pwsh.exe:String) [Start-Job],
PSNotSupportedException
    FullyQualifiedErrorId : IPCPwshExecutableNotFound,Microsoft.PowerShell.Commands.StartJobCommand
    InvocationInfo        :
        MyCommand        : Start-Job
        ScriptLineNumber : 4
        OffsetInLine     : 8
        HistoryId        : 1
        ScriptName       : D:\test.ps1
        Line             : $job = Start-Job -ScriptBlock { Write-Host "I am a job." }

        PositionMessage  : At D:\test.ps1:4 char:8
                           + $job = Start-Job -ScriptBlock { Write-Host "I am a job." }
                           +        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        PSScriptRoot     : D:\Code\Playground\ps-playground
        PSCommandPath    : D:\test.ps1
        InvocationName   : Start-Job
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, D:\test.ps1: line 4
                            at <ScriptBlock>, <No file>: line 1
TargetSite     :
    Name          : Invoke
    DeclaringType : System.Management.Automation.Runspaces.PipelineBase, System.Management.Automation,
Version=7.2.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    MemberType    : Method
    Module        : System.Management.Automation.dll
Message        : The pwsh executable cannot be found at "C:\Users\<username>\.dotnet\tools\.store\powers
hell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe".
                 Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being hosted in
other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.
Data           : System.Collections.ListDictionaryInternal
InnerException :
    Type        : System.Management.Automation.PSNotSupportedException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The pwsh executable cannot be found at "C:\Users\<username>\.dotnet\tools\.store\p
owershell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe".
                      Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being hosted
in other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.
            HResult : -2146233087
        CategoryInfo          : NotImplemented: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : NotSupported
    TargetSite  :
        Name          : ThrowTerminatingError
        DeclaringType : System.Management.Automation.MshCommandRuntime, System.Management.Automation,
Version=7.2.0.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The pwsh executable cannot be found at "C:\Users\<username>\.dotnet\tools\.store\power
shell\7.2.0\powershell\7.2.0\tools\net6.0\any\win\pwsh.exe".
                  Note that 'Start-Job' is not supported by design in scenarios where PowerShell is being hosted in
other applications. Instead, usage of the 'ThreadJob' module is recommended in such scenarios.
    Source      : System.Management.Automation
    HResult     : -2146233067
    StackTrace  :
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
Source         : System.Management.Automation
HResult        : -2146233087
StackTrace     :
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.Runspaces.Pipeline.Invoke()
   at Microsoft.PowerShell.Executor.ExecuteCommandHelper(Pipeline tempPipeline, Exception& exceptionThrown,
ExecutionOptions options)

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions