How to execute Powershell scripts over Cygwin /OpenSSH

Hello,
I am connecting via SSH to a windows host running Cygwin SSHD (OpenSSH) server.
I would like to run powershell scripts on it remotely.

I did try several versions of SSH servers based on OpenSSH and none of them worked so far. (Cygwin SSH, CopSSH, RedHat Cygwin SSH).

The problem is that after connecting (via SSH) and executing powershell.exe, the console does not return to the command prompt  (does not accepty any input at all).
The only way to break the freeze is to do CTRL-C.

Powershell scripts that do not require any console input (e.g. do not ask (Y/N) question) run OK with this command (-n option):

ssh.exe -n user@mysshserver "powershell.exe C:\\\testdir\\\some_script.ps1"  (command typed in PS command prompt on the SSH client side)

Note: if a powershell script requires input (let's say the "some_script.ps1" has command "Read-Host" in it), it will freeze too.

When I make a full connection though (ssh.exe user@myserver) the console doe not come back to the command prompt by running any PS script. (CTRL-C is needed again).


After connecting  - ssh user@sshserver - executing of "powershell.exe" freezes the console (no input accepted) but running "powershell.exe /?" does return the console prompt correctly.

Q. how do I make powershell work over Cygwin SSH work?

Thank you.

P.S.   freeSSHd was the only free SSH server on which PS scripts worked (console was accepting input requests from PS scripts and console would return to the command prompt). I wonder if freeSSHd is in some way based on OpenSSH or it is an independent product. It has other limitations though so I would like to use Cygwin/OpenSSH here.





drnavigatorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lbocCommented:
Hi, I don't know why powershell does not work properly with openssh but I solved my problem by piping the commands I want to run in powershell to the command "powershell -command -"
|
For example to list services on a windows server do:

echo "get-eventlog -logname security"  |  ssh 'the-windows-server' powershell -command -

Regards, Lars
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
drnavigatorAuthor Commented:
Lars,
Thank you for your response.
I have already found the "powershell -command -" workaround since my last post.

If someone has a better solution for running powershell scripts/commands over OpenSSH please add to this post.

Additional note: SSH exec requests seem to execute fine if using the -n switch, e.g:

ssh -n user@server 'powershell c:\\\testdir\\\subdir\\\test.ps1'

Thank you,
Martin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Software

From novice to tech pro — start learning today.