Microsoft's PowerShell for Linux

New Shell on the Beach

© Lead Image © silvae, 123RF.com

© Lead Image © silvae, 123RF.com

Article from Issue 193/2016
Author(s):

Microsoft released its PowerShell under a free license in August 2016 and ported the tool to Linux and Mac OS. Is PowerShell for Linux a mere marketing ploy or a real contender that can compete with native Linux shells?

Microsoft has done its part to perpetuate its image as the bogeyman of the Open Source movement. Who could forget the advertising campaign in which Microsoft gave penguins the mutant heads of other animals – such as a frog with antlers, implying that an open operating system with parts from different places is somehow unnatural? Or when former Microsoft CEO Steve Ballmer called Linux a "cancer" [1]?

For a few years now, however, Microsoft has been toning down its rhetoric and pursuing something more like an appeasement policy, with vague statements about whether Windows would one day have an open license; Microsoft even perplexed the community at one point when it announced it was about to develop its own Linux for its cloud [2].

Recent signs, however, point to genuine improvement in the Microsoft-Linux relationship. A photo from LinuxCon 2016, which made the rounds on social media, showed Linux creator Linus Torvalds standing by the Microsoft booth, comfortably sipping a cup of coffee [3]. In 2000, Torvalds made an April Fools joke out of naming Microsoft as a partner for Linux development work. What once was a joke is now reality, and the biggest evidence of Microsoft's commitment to Open Source is the recent release of the Windows PowerShell command environment under a free license, along with the announcement that Microsoft was porting PowerShell to Linux and Mac OS.

What and Why?

The first major PowerShell release appeared in 2007. The idea of PowerShell is to create an alternative to the cmd.exe command-line tool, which was included on Windows systems until recently. The cmd.exe environment had very limited functionality.

I should also note, for reasons of fairness, that Microsoft considers cmd.exe more of a relic from the past than an up-to-date tool for admins. Microsoft introduced PowerShell to provide a tool for the power user. Over the years, PowerShell has gained many fans and indeed acquired prestige.

The goal of PowerShell is to provide a command-line environment that allows the user to execute commands without going through a GUI. Does Microsoft believe it is offering Linux users added value? What is behind the release of PowerShell for Linux?

The fact that Microsoft wants to promote its .NET framework is likely an important reason for the company's venture into PowerShell for Linux. Part of porting PowerShell to Linux was creating a core .NET platform for the Linux environment. With that platform providing the basis, putting PowerShell on Linux became a comparatively simple exercise.

However, Microsoft is also looking to the cloud. The popularity of Linux instances running in the cloud does not escape Microsoft's watchful eye. Redmond knows its cloud environment will have to support Linux, and by maintaining their own tools for administering both Linux and Windows systems, they can better maintain their position as a player in the server market. The combination of the PowerShell tools, DSC, and the Operations Management Suite makes it possible for you to administrate your own instances on Linux in Microsoft's Azure public cloud.

Basic Features

Under the hood, PowerShell is based on Microsoft's .NET framework. It mixes different methods: On the one hand, PowerShell allows you to execute simple command-line commands, just as admins would be familiar with from Linux. Different commands can also be combined to produce typical shell scripts. PowerShell controls central shell functions on Linux as well, including the ability to redirect the output of a program to another by piping. On the other hand, PowerShell follows an object-oriented approach: You can define methods and objects that then use the methods.

The central pivot points for working with PowerShell are the commandlets. In PowerShell speak, a cmdlet is a .NET class that performs a specified task after launching. Cmdlets are essentially the actual commands, which can be bundled together in the form of scripts or even binaries. Microsoft has invested a lot of work in equipping PowerShell with many useful cmdlets. Straight after installation, there are many commands available, such as for deleting files or directories, creating folders, or displaying the folder contents (Figure 1).

Figure 1: The classic Get-Childitem PowerShell cmdlet is equivalent to the dir command used with cmd.exe.

According to the PowerShell standard, cmdlets must have a unique name consisting of a verb and object. As a result, the cmdlet for deleting folders or files is officially remove-item. Another example: The cmdlet for downloads from the Internet is invoke-WebRequest; if you are accustomed to Linux, an alternative for invoke-WebRequest would be wget or curl.

To make the transition to PowerShell easier for experienced Linux admins, Microsoft alias-mapped common Linux commands to PowerShell cmdlets. After complaints from the user base, however, Microsoft rejected this approach, because it ultimately prevents users from executing the real command-line programs, such as ls or cd.

Installation on Linux

Microsoft is clearly keen to keep entry barriers as low as possible for PowerShell on Linux. The company is making the source code for PowerShell Version 6 available to the public on GitHub, but it is also offering a package version for the major Linux distributions. So it is very easy to get started, for instance, on Ubuntu 16.04 [4].

After the installation of the libunwind8 and libicu55 packages, you can install the PowerShell package with dpkg -i (Figure 2).

Figure 2: After the installation of libunwind8 and libicu55, PowerShell can install with the aid of the .deb product bundle from Microsoft.

The service would be even better if PowerShell came from a real package repository with signed release files, though this may still be too great an effort for Microsoft. Because packages for various RPM-based distributions are also available from the provider, Microsoft would have to convert the repository for several package systems. Even without their own repository, it works: Good job! So all kinds of others software projects can take a big page out of Microsoft's book.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News

njobs Europe
What:
Where:
Country:
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia