Win32-OpenSSH icon indicating copy to clipboard operation
Win32-OpenSSH copied to clipboard

Subsystem for 5.1

Open Hvid opened this issue 2 years ago • 2 comments

"OpenSSH for Windows" version 8.9.1.0

Server OperatingSystem Windows Server 2016 Standard

Client OperatingSystem Windows Server 2022 Standard

Is it possible to have a subsystem for Powershell 5.1? I currently have this working: Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs -NoLogo

I also have these set in registry:

PS C:\Windows\system32> Get-Item HKLM:\SOFTWARE\OpenSSH\


    Hive: HKEY_LOCAL_MACHINE\SOFTWARE


Name                           Property
----                           --------
OpenSSH                        DefaultShell              : C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
                               DefaultShellCommandOption : /c


PS C:\Windows\system32>

When i ssh into the machine with ssh.exe i get Powershell 5.1. When i Invoke-Command from Powershell 7.2.3 on my client, i get into Powershell 7.2.3 on the server as well. Is it possible to enter Powershell 5.1 from 7.2.3?

I was thinking a subsystem for 5.1, but powershell.exe doesn't have the -sshs switch and this doesn't work: Subsystem powershell5 c:/Windows/System32/WINDOW~1/v1.0/powershell.exe -NoLogo

Hvid avatar May 03 '22 09:05 Hvid

It's not in any way supported by MS or the PowerShell team but I came up with a wrapper that can give you what you want https://gist.github.com/jborean93/7d4cb107fa06251b080fa10ec844893e. You would place this script on your host and set the subsystem to Subsystem ... C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:/path/to/script.ps1.

The reason why this is needed is due to some weird problem with how OpenSSH creates an overlapped stdin pipe for processes and .NET Framework's console handles unable to read from such inputs. The script works around this by using a StreamReader over the stdin handle and just exchanging the PSRP input and output as per usual.

jborean93 avatar May 03 '22 20:05 jborean93

Thanks, that works! I hope MS will eventually fix it, but for now i'll use your script.

Hvid avatar May 04 '22 09:05 Hvid