I have Windows Server 2003 with CopSSH installed on it ( Cygwin + sshd ). W would like to be able to run a PowerShell script via SSH session command and then use it's output. Is there such capability ? How to do it ?
Barry Kelly is right.
You need to use my wrapper software that creates hidden console and runs powershell on it.
My page is here: http://sergeybelous.com/shell-terminal/#proxywinconsole.exe
Someone already found my wrapper software and created tutorial here: http://ssh-with-powershell.blogspot.com/2013/07/enable-ssh-with-powershell-and-remove.html
First thing it is good to add PowerShell's executable path to user's PATH environmental variable. We do it by adding to user's .bashrc file line like:
Then we can run PowerShell script just typing in our SSH session
powershell.exe -File "c:\u.ps1"
Of course now we can pipe it to use it's output.
I just wonder why I have to press "Enter" two times in my SSH session after typing the command for it to work.
If you need to run powershell inside cygwin/babun, follow https://code.google.com/p/mintty/issues/detail?id=56#c64 . Bascilly, downloard or compile https://github.com/rprichard/winpty, copy it to your $PATH and then run
This also works with batch scripts that invoke powershell inside.
Administrator@AAAAA-11111:~ $cd /cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0 Administrator@AAAAA-11111:/cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0 $ cmd /k powershell.exe Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS C:\WINDOWS\system32\WindowsPowerShell\v1.0>
this works for me.