PowerShell – Managing Windows PowerShell from Linux Terminal

powershellremote-accesswindows-server-2012

I manage Windows Server 2012 servers. I'm learning PowerShell to manage these servers through command line. My workstation runs Ubuntu and I usually manage Linux servers by connecting via SSH.

Is there a way that I can use Windows PowerShell on Windows Servers from my Linux workstation through command line like SSH access on Linux?

Best Answer

Some options:

  1. Install an SSH server on a Windows machine, SSH in, run Powershell on the Windows box
  2. Run an RDP client on Linux, RDP in, run Powershell on the Windows box
  3. Use Powershell Web Access, hit the POSH WA gateway server with a browser, run Powershell via the browser

http://technet.microsoft.com/en-us/library/hh831611.aspx

I'm not aware of any POSH executables for Linux, so you can't run POSH commands directly from a shell in Linux - you must first get into the Windows machine somehow, like RDP, remote console (DRAC, iLO), SSH, or POSH Web Access.

/Edit- looks like there are some options. http://sharpcodenotes.blogspot.com/2014/01/running-powershell-commands-from-linux.html

You could try and get OpenWSMan to do what you want, but i think you'd have to craft every command like a URL request rather than simply issue the correct Powershell command - as I said, there's no actual Powershell for Linux. You could install the WinRB ruby gem on every Windows machine and then run Ruby code on your Linux box to call Powershell commands.

In neither case does it seem that you will get the interactive Powershell experience, like tab-completion, help, etc. These seem to be for running a script or a single command, and you'll presumably have to capture any errors or other feedback on your own. You're not going to get a first-class solution on Linux.

/Edit again - yes, MSDN says that this will tend to be ugly/clunky. Even the simple/effective solution that he gives looks like no fun.

Although Powershell remoting is built on top of WS-Management, it’s really a protocol within a protocol and trying to interop with PSRP (Powershell Remoting Protocol) directly would essentially require replicating Powershell on the client.