I have a Powershell .ps script which does some elementary stuff in a windows machine. I invoke this script by ssh-ing to the windows machine. The Windows machine has cygwin Open-SSh installed on it.
Problem : the script gets executed but doesn't return back to the SSH session. How do I get the powershell script to end and return control back to SSH session?
Nice and simple solution here:
https://serverfault.com/questions/266535/how-to-run-a-powershell-script-from-cygwin-ssh-session#comment277301_266699
echo "\n" | powershell ....etc.....
Might be a bit late to answer, but we had a similar problem after installing cygwin sshd to run powershell commands on a citrix server from a linux webserver.
We ended up falling on this page: http://epeleg.blogspot.com/2010/06/solution-to-powershell-never-exists.html
Which prompted us to create a batch file with the powershell command inside of it, and the following syntax:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -Command "& { "your powershell script and arguments here" }"<NUL
We just run the batch file instead of calling powershell directly, and use %1 as a variable if we need one in the batch file.
the <NUL at the end tells powershell not to expect input, and makes it quit back to the ssh prompt. I hope this helps you, or someone falling on this thread!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With