PowerShell Open-Sourced!

3
11891

 

PowerShell is an automation and configuration 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 supportable on the Linux and Mac operating systems.

With the advent of DevOps and cloud technologies, customers are experimenting more and more with multi-platform, multi-cloud or multi-OS based applications. This shift in customer demand and set-up environments has led to a new set of challenges for developers and IT administrators who manage such complex infrastructure, 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 interoperable across several platforms, and ensure faster and continuous business delivery.

MS Azure is a growing collection of integrated cloud services that developers and IT professionals use to build, deploy and manage applications. 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 supportable 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 professionals control and automate the administration of the Windows, Linux and Mac OSs as well as the applications 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 administrators can experience a rich interactive scripting language, as well as heterogeneous automation and configuration management that just works perfectly. Also, MS is partnering with a number of industry-leading 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.

Figure 1: Available commands in Powershell

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 installation
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 application, which contains the bundled PowerShell and dependencies:

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

Alternatively, 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 contributing to PowerShell, refer to the GitHub link https://github.com/PowerShell/PowerShell/tree/master/docs/git.

Let’s run some cmdlets
Once the installation 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 information.

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.

Figure 2: Piping in PowerShell

Uninstalling 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 differences between the Bash shell and PowerShell are more with regard to the end-application 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 administrative tasks.
The benefits PowerShell offers to users are:
1. Support for running heterogeneous workloads
2. Interoperable tools for scalability
3. Native Linux management tasks using PowerShell [better error handling]
4. Support for a broad range of programming needs (interactive shell, scripting, system programming, 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 environment. 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 standardisation between various OSs, as Bash and PowerShell will be supported across different operating systems.

3 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here