Skip to content

Start-Job -Credential fails on Linux #7172

Closed

Description

Steps to reproduce

Start Ubuntu 16.04 running in WSL.
Start pwsh-preview (preview 3)
Create another account (sudo adduser test (password: test)
Execute su - test to log in and verify password. Exit that login.

Execute:

Start-Job -Credential (Get-Credential) {whoami} | Wait-Job | Receive-Job

Expected behavior

Outputs

test

Actual behavior

An error has occurred which PowerShell cannot handle. A remote session might have ended.
+ CategoryInfo          : OpenError: (localhost:String) [], PSRemotingDataStructureException
+ FullyQualifiedErrorId : PSSessionStateBroken

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.3
PSEdition                      Core
GitCommitId                    v6.1.0-preview.3
OS                             Linux 4.4.0-17134-Microsoft #112-Microsoft Thu Jun 07 22:57:00 PST 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I see this issue was referenced in #1365 and was closed as fixed. Perhaps a regression?

Activity

  1. MaximoTrinidad commented on Jun 25, 2018

    @MaximoTrinidad

    Hum!

    Is it possible there's an issue with the '-Credential' parameter?

    Good one Keith! Is not working in Linux /MacOS neither. I definitely think is the Credential parameter.
    :)

    linux_startjobcredential_2018-06-25_18-45-56

    macos_startjobcredential_2018-06-25_18-45-56

    It only work in Windows PowerShell Core.

    winpscore_startjobcredential_2018-06-25_18-45-56

  2. rkeithhill commented on Jun 26, 2018

    @rkeithhill
    CollaboratorAuthor

    Maximo Trinidad (@MaximoTrinidad) Thanks for verifying. I'm kind of hoping that we're just missing some configuration.

  3. added
    Issue-Bug
    on Jun 26, 2018
  4. splatteredbits commented on Jan 21, 2021

    @splatteredbits

    This doesn't work in PowerShell 7.0.2, either. :(

    > start-job -Credential $cred {whoami} | receive-job -wait -AutoRemoveJob
    OpenError: An error has occurred which PowerShell cannot handle. A remote session might have ended.
    > $PSVersionTable
    Name                           Value
    ----                           -----
    PSVersion                      7.0.2
    PSEdition                      Core
    GitCommitId                    7.0.2
    OS                             Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
  5. splatteredbits commented on Jan 21, 2021

    @splatteredbits

    Or 7.1.1.

    > start-job -Credential $cred {whoami} | receive-job -wait -AutoRemoveJob
    OpenError: An error has occurred which PowerShell cannot handle. A remote session might have ended.
    > $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.1.1
    PSEdition                      Core
    GitCommitId                    7.1.1
    OS                             Linux 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
    
  6. splatteredbits commented on Jan 23, 2021

    @splatteredbits

    I got a little more information about this from a build on Ubuntu on AppVeyor:

    PlatformNotSupportedException: The Domain property is not supported on this platform.
    PSRemotingDataStructureException: An error has occurred which PowerShell cannot handle. A remote session might have ended.

  7. mklement0 commented on Aug 13, 2021

    @mklement0
    Contributor

    The issue still exists in PowerShell Core 7.2.0-preview.8 and not only (unsurprisingly) also affects macOS, but Windows too, albeit with a different error message:

    OpenError: [localhost] An error occurred while starting the background process. Error reported: Access is denied..
    
  8. iSazonov commented on Aug 13, 2021

    @iSazonov
    Collaborator

    Michael Klement (@mklement0) What is repro steps for Windows?

  9. mklement0 commented on Aug 13, 2021

    @mklement0
    Contributor

    Ilya (@iSazonov), same as Keith Hill (@rkeithhill)'s in the original post (except you need to create another Windows users to target with -Credential).

  10. iSazonov commented on Aug 13, 2021

    @iSazonov
    Collaborator

    /cc Paul Higinbotham (@PaulHigin) for information.

  11. mklement0 commented on Aug 13, 2021

    @mklement0
    Contributor

    For the sake of completeness, I should also mention that Windows PowerShell breaks in yet another way:

    [localhost] An error occurred while starting the background process. Error reported: The directory name is invalid.
    

    In Windows PowerShell, Start-Job uses a fixed working directory for background jobs, namely the calling user's Documents folder, so I presume the problem is that the (by definition non-elevated) target user process isn't permitted to access this directory.

    That said, if you run the Start-Job -Credential command from an elevated session in WinPS, it does succeed (and does use the target user's Documents folder) - but this requirement is neither documented nor should it be necessary, given that runas.exe can run as a different user just fine even from non-elevated sessions.

    Conversely, running Start-Job -Credential in PS Core with elevation also breaks as described.

  12. iSazonov commented on Aug 15, 2021

    @iSazonov
    Collaborator

    so I presume the problem is that the (by definition non-elevated) target user process isn't permitted to access this directory.

    Good point!

    if (WorkingDirectory == null)
    {
    try
    {
    WorkingDirectory = SessionState.Internal.CurrentLocation.Path;
    }
    catch (PSInvalidOperationException)
    {
    }
    }

    Comes from #10920

    I guess it is not single place where setting CWD may cause an issue.

  13. mklement0 commented on Aug 18, 2021

    @mklement0
    Contributor

    A workaround for Windows PowerShell (doesn't help in PS Core):

    As someone figured out on Stack Overflow, the problem can be worked around by setting the process-level working directory to one the target user is permitted to access:

    # Works.
    [environment]::CurrentDirectory = 'C:\'; Start-Job -Credential (Get-Credential otheruser) { whoami } | Receive-Job -Wait -AutoRemoveJob
  14. added
    Resolution-No Activity
    on Nov 16, 2023
  15. 2d1a0ec3 commented on May 23, 2024

    @2d1a0ec3

    Just tested it with PowerShell 7.4.1 and I get the same error as OP.

    Start-Job -Credential (Get-Credential) {whoami} | Wait-Job | Receive-Job
    
    OpenError: An error has occurred which PowerShell cannot handle. A remote session might have ended.
    
    >$PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      7.4.1
    PSEdition                      Core
    GitCommitId                    7.4.1
    OS                             Ubuntu 24.04 LTS
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
  16. added
    WG-Cmdlets
    and removed on Jul 17, 2026
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-BugResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions