Skip to content

PowerShell Core cannot start a job using Windows PowerShell #7059

Closed

Description

When -PSVersion is specified, it should be respected. And all supported PSVersions (2.0 to 5.1) should be supported when the corresopnding version of Windows PowerShell is available.

Note that, when -PSEdition 2.0 is specified, Start-Job checks if PSv2 is installed using the method RemotingCommandUtil.CheckIfPowerShellVersionIsInstalled which will blindly throw exception in PSCore (see code below). If we want to support -PSEdition 2.0, then the #if CORECLR section of the method body should be removed.

        internal static void CheckIfPowerShellVersionIsInstalled(Version version)
        {
            // Check if PowerShell 2.0 is installed
            if (version != null && version.Major == 2)
            {
#if CORECLR
                // PowerShell 2.0 is not available for CoreCLR
                throw new ArgumentException(
                    PSRemotingErrorInvariants.FormatResourceString(
                        RemotingErrorIdStrings.PowerShellNotInstalled,
                        version, "PSVersion"));
#else
                // Because of app-compat issues, in Win8, we will have PS 2.0 installed by default but not .NET 2.0
                // In such a case, it is not enough if we check just PowerShell registry keys. We also need to check if .NET 2.0 is installed.
                ...

Steps to reproduce

PS:1> $job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1
PS:2> Receive-Job $job

Expected behavior

PS:2> Receive-Job $job

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17134  81

Actual behavior

PS:2> Receive-Job $job

Major  Minor  Patch  PreReleas BuildLabel
                     eLabel
-----  -----  -----  --------- ----------
6      0      1

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. BrucePay commented on Jun 13, 2018

    @BrucePay
    Collaborator

    However, in PowerShell Core, we can only start job using pwsh. So the whole -PSVersion parameter doesn't really make sense.

    I believe this is a bug (see #7052). Basically we've hard-coded what gets run when we start a job. There is no reason for this. We should be able to start a WindowsPowerShell job.

  2. changed the title [-]Clean up PSv2 related code in code base[/-] [+]PowerShell Core cannot start a job using Windows PowerShell[/+] on Jun 13, 2018
  3. daxian-dbw commented on Jun 13, 2018

    @daxian-dbw
    MemberAuthor

    Bruce Payette (@BrucePay) I have changed this issue to only track the Start-Job -PSVersion problem.
    It turns out my comment about PSCore remoting to PSv2 server was not accurate. WMF 4.0 is required for setting up a PSCore endpoint, but it might not require WMF 4.0 for PSCore to connect to a PSv2 server. That means it's possible we still need to handle PSv2 server in remoting code.

  4. added
    Issue-Bug
    WG-Engine
    on Jun 13, 2018
  5. anmenaga commented on Jan 3, 2020

    @anmenaga

    This is fixed in 7.0.0-rc.1 for -PSVersion 5.1:

    PS C:\> $PSVersionTable.PSVersion
    
    Major  Minor  Patch  PreReleaseLabel BuildLabel
    -----  -----  -----  --------------- ----------
    7      0      0      rc.1
    
    PS C:\> $job = Start-Job { $PSVersionTable.PSVersion } -PSVersion 5.1
    PS C:\> Receive-Job $job
    
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    5      1      14393  3383
    
  6. daxian-dbw commented on Jan 3, 2020

    @daxian-dbw
    MemberAuthor

    Andrew (@anmenaga) I think supporting -PSVersion 5.1 should be sufficient to close this bug, right?

  7. anmenaga commented on Jan 6, 2020

    @anmenaga
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

    Issue-BugWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions