A First Look At PowerShell on Linux

powershell hero
If you had any doubts that the Microsoft of today is vastly different from the Microsoft you grew up with, I think the news out of Redmond today should put those doubts to rest. Microsoft has finally put all the speculation to rest and announced that PowerShell is now an open source project released under the MIT license. This is a monumental step for a company long known for it’s proprietary ways but for those of us in the PowerShell community it doesn’t come as a total surprise. PowerShell creator and Microsoft Technical Fellow Jeffrey Snover has never hidden his hopes of  PowerShell open source. As you might imagine, for a company like Microsoft that is not a quick process.

But today everything changes.
Even though I’m talking about PowerShell going open source, this is possible because Microsoft has invested significant resources in developing a Core edition of the .NET Framework. The .NET Core Framework is also an open source project. If you are interested in learning more visit the DotNetFoundation.org site. I mention this because the open source version of PowerShell is based on the .NET Core which means (as it always has) if there are limitations or dependencies in .NET there will be limitations in PowerShell. But don’t take that as a criticism it is merely an observation.
So what do we get? Microsoft is announcing that you can now run an open source version of PowerShell on these platforms:

  • Windows 8.1/Windows Server 2012 R2
  • Windows 10/Windows Server 2016
  • Ubuntu 14.01
  • Ubuntu 16.04
  • CentOS 7
  • OS X 10.11

Yes, this means you can now run PowerShell on Mac and Linux! Personally, I think this is a major step in the right direction towards the goal of using PowerShell to manage everything, even non-Windows platforms or even from a non-Windows platform. Of course, we’re not 100% there yet as the bits available today are clearly alpha level. But every journey has to begin somewhere.

PowerShell on Linux

In hopes of getting you even more excited about this news allow me to share some shots of PowerShell running on a Ubuntu 16.04 desktop. This install process is pretty simple and when you are finished you can open a terminal session and run ‘powershell’.

launching PowerShell on Ubuntu
launching PowerShell on Ubuntu (Image Credit: Jeff Hicks)

You probably never thought you’d see that in a legitimate screen shot. It will be very important to check the $PSVersionTable variable to check your version.
Ubuntu PSVersionTable
Ubuntu PSVersionTable (Image Credit: Jeff Hicks)

PowerShell on Linux, especially this alpha, will be a very different experience than what you may be used to on Windows.  We only have a subset of modules and commands.
Command Subset on Linux
Command Subset on Linux (Image Credit: Jeff Hicks)

Many commands that don’t make sense on Linux like Get-Service and Get-Eventlog have been removed. But others should behave just as you expect, including help.
PowerShell help on Linux
PowerShell help on Linux (Image Credit: Jeff Hicks)

When you run PowerShell commands in Linux you are working with objects which means you can create the same type of pipelined expressions as you would in Windows.
Working with objects on Linux
Working with objects on Linux (Image Credit: Jeff Hicks)

 
PowerShell pipelines on Linux
PowerShell pipelines on Linux (Image Credit: Jeff Hicks)

One major difference, at least for now, is that in a Linux PowerShell session, the Linux-style aliases we have in Windows like ls and ps, have been removed. This means that in a PowerShell session you can use the native command or the PowerShell equivalent.
Native Linux Commands not Aliases
Native Linux Commands not Aliases (Image Credit: Jeff Hicks)

What to do with Linux aliases is at least one area the PowerShell team will by relying on the community for guidance.

Limitations

I have not tested the Mac implementation but at least from the Linux side don’t expect everything to work as it does in Windows today. There are a number of areas that are still being addressed and I expect some of them will require additional open source implementations.
The most significant limitation, in my opinion, is that there is no remoting or remote computer capabilities. Microsoft is planning on an update to address this issue and most likely it will include support for OpenSSH as a native remoting protocol. Related to this issue, we won’t have any background or scheduled job capabilities either. And finally there is no support for WMI or CIM. The latter I think will eventually appear through other open source initiatives but for now there are no WMI or CIM commands that you can run on Linux but definitely keep an eye out in this space as the Operations Management Suite (OMS) continues to evolve.
I know that most of the time we tend to skip looking at README files, but take a few minutes to read the release notes and especially the Known Issues document.

What About Windows?

But what about all your Windows servers that you manage today from a Windows 10 desktop? Microsoft’s intention is to release supported versions of PowerShell based on the open source bits, but I’m assuming with all the features you’ve come to suspect. In other words, when Windows Server 2016 ships I expect it to offer the same full-on PowerShell experience you are familiar with.

Next Steps

First, if you haven’t already done so be sure to read the official announcement from Jeffrey Snover. Then head to https://github.com/PowerShell/PowerShell and download the Alpha releases that interest you. Then you have to decide where you want to contribute and how you want to take part in this journey. Clearly what is being release today is but a small piece of the PowerShell ecosystem and Microsoft is relying on the community to help drive it forward.
We’ll have more coverage in the weeks to come about this exciting next step for PowerShell. For those of you who have invested in learning PowerShell I think it is about to pay off in a big way. And for the rest of you, it’s never to late to start learning. Let’s get going.