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
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.
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?
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.
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..
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 -Credentialin PS Core with elevation also breaks as described.
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:
Activity
MaximoTrinidad commentedon Jun 25, 2018
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.
:)
It only work in Windows PowerShell Core.
rkeithhill commentedon Jun 26, 2018
Maximo Trinidad (@MaximoTrinidad) Thanks for verifying. I'm kind of hoping that we're just missing some configuration.
splatteredbits commentedon Jan 21, 2021
This doesn't work in PowerShell 7.0.2, either. :(
splatteredbits commentedon Jan 21, 2021
Or 7.1.1.
splatteredbits commentedon Jan 23, 2021
I got a little more information about this from a build on Ubuntu on AppVeyor:
mklement0 commentedon Aug 13, 2021
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:
iSazonov commentedon Aug 13, 2021
Michael Klement (@mklement0) What is repro steps for Windows?
mklement0 commentedon Aug 13, 2021
Ilya (@iSazonov), same as Keith Hill (@rkeithhill)'s in the original post (except you need to create another Windows users to target with
-Credential).iSazonov commentedon Aug 13, 2021
/cc Paul Higinbotham (@PaulHigin) for information.
mklement0 commentedon Aug 13, 2021
For the sake of completeness, I should also mention that Windows PowerShell breaks in yet another way:
In Windows PowerShell,
Start-Jobuses a fixed working directory for background jobs, namely the calling user'sDocumentsfolder, 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 -Credentialcommand from an elevated session in WinPS, it does succeed (and does use the target user'sDocumentsfolder) - but this requirement is neither documented nor should it be necessary, given thatrunas.execan run as a different user just fine even from non-elevated sessions.Conversely, running
Start-Job -Credentialin PS Core with elevation also breaks as described.iSazonov commentedon Aug 15, 2021
Good point!
PowerShell/src/System.Management.Automation/engine/remoting/commands/StartJob.cs
Lines 614 to 623 in eeb0407
Comes from #10920
I guess it is not single place where setting CWD may cause an issue.
mklement0 commentedon Aug 18, 2021
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:
2d1a0ec3 commentedon May 23, 2024
Just tested it with PowerShell 7.4.1 and I get the same error as OP.