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 ?

link|improve this question

67% accept rate
feedback

2 Answers

up vote 5 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.

link|improve this answer
Thanks. I did not think it's that simple. – malloc4k May 5 '11 at 13:43
feedback

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.

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

Your Answer

 
or
required, but never shown

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