32

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?

5
  • There are 3rd party products that provide an SSH server for Windows with powershell as the default shell. e.g. powershellserver.com
    – Zoredache
    Oct 21 '14 at 20:42
  • 7
    Personally I prefer to manage Windows from a Windows (virtual) machine, and Linux from a Linux machine. This seems to be helping to preserve what's left of my sanity. Oct 21 '14 at 21:38
  • I get what you're trying to achieve, but so long as you can run powershell commands on one windows host couldn't you manage the others from that PS session?
    – Andy
    Oct 22 '14 at 7:47
  • @Andy - my point exactly.
    – mfinni
    Oct 22 '14 at 12:47
  • I am getting interested in the Pash project (github.com/Pash-Project/Pash). They want to reimplement PowerShell on Linux. I am now trying to compile on a Raspberry Pi machine to see if I can remotely issue a shutdown command Mar 1 '16 at 20:59
16

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.

7
  • This can do the job... but I have to install the SSH server on every Windows Server. As far as I know, PowerShel uses WS-Management, an Open Standard... there is any Linux client that make this kind of connection?
    – Ederson
    Oct 21 '14 at 20:37
  • 2
    No sir. Once you have a shell on a Windows box (assuming it's in the same domain as the other Windows boxes) you can use Powershell Remoting. Or you can use DSC, Desired State Config. Or you might be working on things like AD or MS Exchange that don't operate on a single server anyway, but connect to the directory using whatever DC or CAS server is available.
    – mfinni
    Oct 21 '14 at 20:39
  • 2
    Once you have a shell on a Windows box you can use Powershell Remoting. - Do be aware that you will almost certainly run into the 2-hop authentication issue with this. You almost certainly will need to use CredSSP authentication.
    – Zoredache
    Oct 21 '14 at 20:45
  • Will he run into this issue if pursuing either of the first two methods? I (think I) know that you don't have this problem using RDP.
    – mfinni
    Oct 21 '14 at 20:46
  • 1
    Just to note, Pash (github.com/Pash-Project/Pash) might potentially have this capability at some point, but that will likely be pretty far off into the future. They're still trying to just get the basics of PowerShell implemented for now. Apr 16 '15 at 22:40
6

Microsoft is officially releasing Powershell on Linux and OSX. See the August 2016 announcement: PowerShell is open sourced and is available on Linux

It's currently in alpha. Ubuntu and Centos are officially supported, more on the way. If you're adventurous, installation instructions are available here: https://github.com/PowerShell/PowerShell/blob/master/docs/installation/linux.md

4

Yes, you have 2 options:

  1. You can install SSHd server on windows and in configuration set up path to the PowerShell.

    For this you can use tutorial for installation of SSHd and configuration PowerShell path.

    In short:

    1. Install freeSSHd
    2. Add new user account and allow SSH access
    3. Enable SSH port in Windows Firewall
    4. Configure path to PowerShell.exe
  2. PowerShell Web Access (Only Win Server 2012 R2)

    There you have one tutorial on Technet -- blogs.technet.com/b/canitpro/archive/2013/11/14/step-by-step-deploy-powershell-web-access.aspx

2
  • This can do the job... but I have to install and configure the SSH server on every Windows Server. As far as I know, PowerShell uses WS-Management, an Open Standard... there is any Linux client that make this kind of connection?
    – Ederson
    Oct 21 '14 at 20:39
  • I added one option with link, if you can 2012 R2 then this can help you. But still is not "built-in" and with client. You access it over browser.
    – zorbon.cz
    Oct 21 '14 at 21:04
3

Tested in Ubuntu 14.04 LTS

Download and install winexe:

wget https://passing-the-hash.googlecode.com/files/winexePTH1.1.0-1.deb

dpkg -i winexePTH1.1.0-1.deb

Basic usage

winexe -U DOMAIN/USERNAME%PASSWORD //MACHINEIP "cmd.exe"

As an example:

echo -ne '\n' | winexe -U DOMAIN/USERNAME%PASSWORD //IP 'powershell.exe -command "Get-Process | Select-Object Name, ProcessName"' | sort -u
1
  • 2
    Please add some more details to explain this answer ... Apr 7 '16 at 8:09
2

You can also install win32-openSSH by hand from https://github.com/PowerShell/Win32-OpenSSH or through Chocolatey https://chocolatey.org or even faster through Boxstarter (which utilizes Chocolatey under the hood) https://boxstarter.org (fast install https://boxstarter.org/packages/nr/win32-openssh ).

It takes a little setup, but it is a native (yeah, for real!) win32 port maintained by the Microsoft guys doing PowerShell.

Otherwise as somebody mentioned you could install the WinRM gem on Linux and get a little bit of connectivity over the WinRM protocol, but that's not as nice as just starting a PSSession.

Additionally the folks behind the WinRM gem (WinRb) are also looking at implementing a more native PowerShell interaction that tunnels PowerShell over WinRM which will be more functional for uploads and faster for other operations as well. See this blog post: http://www.hurryupandwait.io/blog/a-look-under-the-hood-at-powershell-remoting-through-a-ruby-cross-plaform-lens

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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