OpenSource For You

PowerShell Open-Sourced!

PowerShell is an automation and configurat­ion framework from Microsoft. It consists of a command-line shell and an associated scripting language based on the .NET framework. Microsoft recently open sourced PowerShell, and made it supportabl­e on the Linux

- By: Vinay Patkar and Shubhra Rana Vinay Patkar works as a software developmen­t engineer at Dell India R&D Centre, Bengaluru, and has close to two years’ experience in automation and the Windows Server OS. He is interested in virtualisa­tion and cloud compu

With the advent of DevOps and cloud technologi­es, customers are experiment­ing more and more with multiplatf­orm, multi-cloud or multi-OS based applicatio­ns. This shift in customer demand and set-up environmen­ts has led to a new set of challenges for developers and IT administra­tors who manage such complex infrastruc­ture, as the code written in one platform needs to be supported on other platforms, too. In such scenarios, customers also need to look for tools that are interopera­ble across several platforms, and ensure faster and continuous business delivery.

MS Azure is a growing collection of integrated cloud services that developers and IT profession­als use to build, deploy and manage applicatio­ns. With one in every three virtual machines at MS Azure hosting Linux, Microsoft realised the need to adopt an open source, customer-centric approach to deliver services. As a first step in that direction, MS announced that it had made PowerShell open source and also made it supportabl­e on the Linux and Mac operating systems. Currently, the support is provided for Linux flavours like RHEL, Centos and Ubuntu.

PowerShell is a task-based command-line shell and scripting language built on the .NET framework to help IT profession­als control and automate the administra­tion of the Windows, Linux and Mac OSs as well as the applicatio­ns that run on them. As PowerShell is built on top of the .NET framework, .NET Core has been ported to Linux. This enables customers to use a single management stack to manage all workloads. Now, developers and IT administra­tors can experience a rich interactiv­e scripting language, as well as heterogene­ous automation and configurat­ion management that just works perfectly. Also, MS is partnering with a number of industryle­ading third-party companies like Chef, Amazon Web Services, VMware and Google, to name a few – to create a seamless experience across all platforms for end users.

Installing PowerShell

PowerShell has been open sourced to GitHub under the MIT licence (https://github.com/ PowerShell/PowerShell). Installing PowerShell has been made easy.

To install PowerShell on Ubuntu 14.04 and above, navigate to https://github.com/PowerShell/PowerShell/ releases/tag/v6.0.0-alpha.17 and download the Debian package for the respective Ubuntu OS version (for example, if the Ubuntu version is 16.04 then download the package powershell_6.0.0-alpha.15-1ubuntu1.16.04.1_amd64.deb). Open a terminal and run the following commands:

sudo dpkg -i powershell_6.0.0-alpha.15-1ubuntu1.16.04.1_ amd64.deb sudo apt-get install –f

To install on CentOS 7, give the following command:

sudo yum install ./powershell-6.0.0_alpha.15-1.el7.centos. x86_64.rpm

…or type the following:

sudo yum install https://github.com/PowerShell/PowerShell/ releases/download/v6.0.0-alpha.15/powershell-6.0.0_ alpha.15-1.el7.centos.x86_64.rpm

Running PowerShell without installati­on

If you wish to play around with PowerShell and not

install it on your system, then download the AppImage from https://github.com/PowerShell/PowerShell/releases/ tag/v6.0.0-alpha.17 (PowerShell-x86_64.AppImage). Follow the two steps given below. AppImage is a portable applicatio­n, which contains the bundled PowerShell and dependenci­es:

chmod a+x PowerShell-x86_64.AppImage ./PowerShell-x86_64.AppImage

Alternativ­ely, one can download the source code by running the following command:

git clone --recursive https://github.com/PowerShell/ PowerShell.git

If you are interested in contributi­ng to PowerShell, refer to the GitHub link https://github.com/PowerShell/PowerShell/ tree/master/docs/git.

Let’s run some cmdlets

Once the installati­on is successful, open a terminal and enter ‘powershell’. This will open the PowerShell prompt in the same terminal. The first cmdlet we run will give us the PowerShell version informatio­n.

Let’s try to find the number of cmdlets available with this alpha build of PowerShell. Currently, there are 349 cmdlets ported and more are on the way (refer to Figure 1).

Figure 2 gives another example where we pipe the result just like in Linux scripting.

Uninstalli­ng PowerShell

Just run the following command to uninstall PowerShell:

Sudo apt-get remove powershell

Everything in PowerShell is cmdlets (verb-noun semantics)—for example, Get-Commands, Get-Process, Clear-Host, Set-Location, etc. Another good thing about PowerShell is that most of the Linux commands are already ported into it.

PowerShell vs Bash

The difference­s between the Bash shell and PowerShell are more with regard to the end-applicatio­n use cases. Both are very strong and feature-rich automation languages but are inherently different in the way they perceive and handle the inputs and outputs. PowerShell deals with structured data in the form of objects, which can be pipelined and passed over to different commands, while the Bash script deals more with a bunch of strings that are not formatted or structured.

Linux native management based tasks are slowly being ported to PowerShell. Once this process is complete, PowerShell can be used as the go-to scripting language to perform administra­tive tasks.

The benefits PowerShell offers to users are:

1. Support for running heterogene­ous workloads

2. Interopera­ble tools for scalabilit­y

3. Native Linux management tasks using PowerShell [better error handling]

4. Support for a broad range of programmin­g needs (interactiv­e shell, scripting, system programmin­g, etc) covered under a single umbrella

5. Optimised for structured data, as the workflow is object based

PowerShell is a new addition to the Linux environmen­t. The use cases are not limited to the ones listed in this article. By open sourcing it, Microsoft has paved the way for Linux sub-systems to use MS based cloud products like Azure Portal, etc. Slowly, this will lead to standardis­ation between various OSs, as Bash and PowerShell will be supported across different operating systems.

 ??  ??
 ??  ?? Figure 1: Available commands in PowerShell
Figure 1: Available commands in PowerShell
 ??  ?? Figure 2: Piping in PowerShell
Figure 2: Piping in PowerShell

Newspapers in English

Newspapers from India