I have a windows server 2016 (version 1607, build 14393) with OpenSSH installed and running.

Recently, I noticed that I am no longer able to run powershell from a remote client when connecting via SSH, and keep getting the 'Powershell' is not recognized as an internal or external command, operable program or batch file error.

I also tried running it locally via CMD, and got the same error above. I followed this question and discovered I was suddenly missing an environment variable path to powershell. By adding %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ to my Path I was able to run powershell locally again via CMD.

Yet even with this fix I am still unable to run powershell when connected using SSH, which is even more strange, as SSH connections are always ran as CMD in windows by default.

Here is an example of my connection process (running from ubuntu 16.04 terminal):

foo@foo:~$ ssh administrator@_SERVER_IP_
administrator@_SERVER_IP_'s password:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

administrator@_SERVER_IP_ C:\Users\Administrator>powershell
'Powershell' is not recognized as an internal or external command,  operable program or batch file.

Any hint what might be the cause for this problem?

Edit: While on SSH, the output of where powershell.exe command is INFO: Could not find files for the given pattern(s).

  • Did you add the variable to the System or User Environment PATH? Jun 8 '20 at 13:22
  • execute where powershell.exe in a regular command-line and the check if the shown path in the PATH env when you access the server via ssh.
    – Robert
    Jun 8 '20 at 13:27
  • @Robert When ran locally on cmd, the output is as expected: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe. This is also the env variable added manually to fix the problem locally. While on SSH, the output of this command is INFO: Could not find files for the given pattern(s).
    – Pizza
    Jun 9 '20 at 6:52

I managed to bypass this problem, yet this is not a fix for it. I configured OpenSSH to use powershell as a default shell for any new SSH connection, and not the default CMD. If needed, I can launch cmd from powershell, though it is useless once using powershell, as it also supports every CMD command.

From Microsoft documentation: OpenSSH Server Configuration for Windows 10 1809 and Server 2019 (This also works for windows server 2016).

Simply create a registry key at HKLM:\SOFTWARE\OpenSSH, with a type of string, named DefaultShell and a value of C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

This will take effect for any new SSH connection established.

This may also be done by a powershell command: New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

Once again, this is not a fix, and only changes the default shell to powershell (means that if you run 3rd party shells by default such as bash, they will be changed to powershell).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.