Repository navigation
Closed
Labels
Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-RemotingPSRP issues with any transport layer
Milestone
Description
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 $sessionExpected 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 : CouldNotAutoloadMatchingModuleUsing 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\ModulesEnvironment 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.1Metadata
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
Activity
dantraMSFT commentedon Sep 6, 2018
The problem occurs when the PSModulePath from the native environment contains a reference to a SxS installation.
ModuleIntrinsics.GetModulePath calls RemoveSxSPsHomeModulePath to remove it; which succeeds but the subsequent logic is has a few problems. In the repro case, systemModulePathToUse is populated with the PSHOME\Modules because hklmMachineModulePath is null and it is placed at the end of the PSModulePath. Using the pshome\modules path as the fallback is problem since later logic assumes they are different.
For the repro case, I was using 6-preview as the default shell for OpenSSH and using RC-1 as the subsystem. OpenSSH adds the path of the default shell to the PSModulePath environment variable which is picked up by the subsystem process.
dantraMSFT commentedon Sep 6, 2018
The problem occurs when the environment's path already contains the Windows PowerShell module path (%windir%\system32\WindowsPowerShell\v1.0\Modules).
The current logic conditionally appends it if it is not present but doesn't consider it when adding $PSHOME\Modules. The result is $PSHOME\Modules is added after Windows PowerShell causing built in modules to be loaded from Windows PowerShell; many of which fail.
The problem only occurs when SxS versions of PowerShell containing the PSCompatibleEdition changes are installed and one launches the other or if the Windows PowerShell module path is present in the environment's PSModulePath.
A possible fix is to detect the existence of WP's module path and insert $PSHOME\Modules before it.
SteveL-MSFT commentedon Sep 7, 2018
Talked to Dan Travison (@dantraMSFT), this seems more of an advanced use case than a common case for most users. If the fix comes in and is low risk, we can consider for 6.1 GA, but it's not a blocker for GA.
dantraMSFT commentedon Sep 7, 2018
Steve Lee (@SteveL-MSFT): The proposed fix and test are here: #7727
Update PowerShell to handle the case where the Windows PowerShell mod…
Update PowerShell to handle the case where the Windows PowerShell mod…