Skip to content

Using PowerShell Core RC-1 as an OpenSSH subsystem on windows breaks core module loading #7679

@dantraMSFT

Description

@dantraMSFT

Steps to reproduce

  • Install OpenSSH on Windows Server 2016

  • Configure PowerShell as a subsystem
    NOTE: Due to path issues, create a symlink or copy PowerShell Core to a directory without spaces
    Subsystem powershell c:\powershell\pwsh.exe -sshs -NoLogo -NoProfile

  • Connect from a linux or windows system

$session = New-PSSession -HostName hostname -UserName username
Enter-PSSession $session

Expected behavior

The session is entered.

Actual behavior

The command fails

PS /home/psrptest> enter-pssession $session
enter-pssession : The 'Measure-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At line:1 char:1
+ enter-pssession $session
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Measure-Object:String) [Enter-PSSession], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Using Invoke-Command to invoke Test-Path on the session also produces an error due to failing to load 'Microsoft.PowerShell.Management'

PS /home/psrptest> Invoke-Command -Session $session -ScriptBlock {Test-Path -Path C:\Windows}
The 'Test-Path' command was found in the module 'Microsoft.PowerShell.Management', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Management'.
+ CategoryInfo          : ObjectNotFound: (Test-Path:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
+ PSComputerName        : psrpwinsrv.fsm0dauomfbubcgw4wlghhwv3d.yx.internal.cloudapp.net

Using Invoke-Command to examine $env:PSModulePath, it appears suspicious in that $PSHOME is the last entry in the apath.

PS /home/psrptest> Invoke-Command -Session $session -ScriptBlock {$PSHOME}
C:\powershell
PS /home/psrptest> Invoke-Command -Session $session -ScriptBlock {$env:PSModulePath}
C:\Users\psrptest\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;c:\powershell\Modules

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSRemotingProtocolVersion      2.3
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
GitCommitId                    6.1.0-rc.1
PSEdition                      Core
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PSVersion                      6.1.0-rc.1

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-RemotingPSRP issues with any transport layer

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions