Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi 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 ?

share|improve this question

2 Answers

up vote 6 down vote accepted

Just invoke powershell with the relevant arguments and pipe it to wherever you want it? You need to make sure it's in the PATH of course.

share|improve this answer
Thanks. I did not think it's that simple. – malloc4k May 5 '11 at 13:43
1  
It's not that simple. PowerShell uses the Console API; Cygwin (in the hands of experienced users) is not run in the console, it's run in a terminal emulator. PowerShell doesn't work in a terminal; it hangs because it's trying to use ReadConsoleInput instead of ReadFile on standard input. – Barry Kelly Jun 15 '12 at 10:27

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:

export PATH=${PATH}:"/cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0"

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.

share|improve this answer
2  
To avoid having to hit return, run the command like: echo "\n" | powershell.exe ... – Andrew Jul 23 '11 at 18:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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