Microsoft's PowerShell for Linux
New Shell on the Beach
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).
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).
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
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.