How to run a PowerShell script from Cygwin SSH session?

Posted on

A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about How to run a PowerShell script from Cygwin SSH session? was one problem in server stack that need for a solution. Below are some tips in manage your windows server when you find problem about windows, ssh, powershell, cygwin, copssh.

I have Windows Server 2003 with CopSSH installed on it ( Cygwin + sshd ). I would like to be able to run a PowerShell script via SSH session command and then use its output. Is there such a capability? How to do it?

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.

Barry Kelly is right.

You need to use my wrapper software that creates a hidden console and runs PowerShell on it.

My page is here:
http://sergeybelous.com/SHELL-TERMINAL.html#proxywinconsole.exe

Someone already found my wrapper software and created a tutorial here:
https://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:

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.

Try it with no inputformat

powershell.exe -inputformat none -noprofile echo hello

Can be useful for not having to deliver a file to the local machine.

Leave a Reply

Your email address will not be published. Required fields are marked *