PowerShell is a powerful and flexible shell and scripting language from Microsoft. It used to be restricted to Windows only, but a new cross-platform wind is blowing from Redmond. Microsoft loves Linux, in fact, it joined the Linux foundation as a platinum member. Visual Studio runs on Mac and can build apps for all platforms and all operating systems (desktop, cloud, mobile). PowerShell 6 (currently in Alpha) will be cross-platform and run on Mac and Linux in addition to Windows.
I've used PowerShell fairly extensively in the past, and I still use it today. I develop in a cross-platform environment where some people use Windows and some people use Macs as development machines. In addition we deploy on Linux. I happen to use a Windows laptop at the moment. I use on my Windows laptop 4 different shells! PowerShell (of course), Git-Bash, Msys-2 (need to compile some native code with mingw) and plain Bash inside Linux VMs and Docker containers. In each environment I have a profile with shortcuts and aliases, favorite tools and other goodies. I feel comfortable with this mess, but most people prefer a little more sane environment and use the same skills and tools across as many domains and environments as possible. In this article we'll look into where PowerShell is today, where it's going and why this is an exciting development in particularly for large organization in the enterprise.
The State of PowerShell
PowerShell is in a great position today. It is recognized widely as a great engineering effort. It has effectively replaced the inferior command prompt and batch files on Windows for all new products and projects. It is slated to become the default shell in the next build of Windows 10. The Alpha version of PowerShell 6 is available for download here.
Trying PowerShell on Linux
I don't have a Mac available right now, so I installed PowerShell on a Linux VM. It was pretty painless. I launched a Ubuntu 16.04 VM using Vagrant. I SSH'ed into the VM and ran the following commands
wget https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.13/powershell_6.0.0-alpha.13-1ubuntu1.16.04.1_amd64.deb sudo dpkg -i v6.0.0-alpha.13/powershell_6.0.0-alpha.13-1ubuntu1.16.04.1_amd64.deb
Some dependencies were missing, so I installed them first and then installed PowerShell itself again
sudo apt-get -yf installed sudo dpkg -i v6.0.0-alpha.13/powershell_6.0.0-alpha.13-1ubuntu1.16.04.1_amd64.deb
And that was it. PowerShell is installed as "/usr/bin/powershell". Now, you can just launch PowerShell by typing "powershell" in the terminal.
This is running a PowerShell command on Linux that lists all the processes called system:
get-process systemd Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName ------- ------ ----- ----- ------ -- -- ----------- 0 0 0 1 63.970 1 1 systemd 0 0 0 1 22.380 29825 825 systemd PS /home/vagrant>
The Best Tool For the Job Myth
How many times did you hear the phrase, "Use the best tool for the job?" Guess not. There is no best tool for the job. The best tool depends on much more than the job. It depends on the environment, it depends on the skill level and comfort of the person doing the job and their co-workers with the tool. The same job (automating a workflow) will be best served by a Bash script, a PowerShell script, a Python script, a Fabric script, a Web application or an orchestration framework such as Ansible or Chef. It all depends on the situation. Having PowerShell available on other platforms means that it can become the best tool in more use cases. This is a major factor in cross-platform environments.
The Large Organization Angle
Large organizations have hybrid systems and hybrid teams. They acquire other companies, their technology and their staff. A company that uses platform-specific technology like PowerShell used to be problematic on both ends of the deal. A large company that uses PowerShell extensively will have a hard time integrating Bash-intensive solution and will probably have to resort to run different components in VMs with slow and cumbersome interfaces. Being a small company committed to PowerShell may render you as a less attractive target for acquisition due to difficulties in merging the technology and the people. That also means that many startup companies used to avoid Microsoft technologies such as .NET and PowerShell from the get go. Now, large organizations should feel more comfortable adopting .NET/PowerShell-based solution as well fell more comfortable about integrating smaller teams. While .NET has been cross-platform for a while via the Mono project, and even more now with .NET code, PowerShell was an obstacle for a smooth cross-platform experience.
Use Cases for Using PowerShell on Mac or Linux
Let's look as several common situations where PowerShell can help.
Collaborating with Designers (or other Mac-bound colleagues)
Designers often use Macs as their development platform. Many developers prefer Macs as well. If your system is .NET-based you can run it on Mac, but if it requires some scripting support you wouldn't have to develop two sets of scripts (PowerShell and Bash) and keep them in sync. You can be PowerShell across the board.
Deploying services with Windows heritage on Linux
Many organizations like open options for deployment. This is especially true for cloud applications. If you migrate a service that was deployed on Windows before to a Linux environment then it can help a lot if you can just use your PowerShell scripts to deploy on Linux instead of translating them to Bash or similar. It goes doubly so if you need to deploy both on Windows and Linux (e.g. if you need to deploy locally for testing on development boxes).
Letting people with PowerShell skills be productive in Linux environment
Suppose you're a pure Linux shop or making the switch to Linux. Your pool of engineers can now include people coming from a Windows/PowerShell background that will be immediately productive in the Linux environment using their PowerShell mojo.
Powershell coming to Mac and Linux will significantly increase its reach and relevance in the Enterprise. It will also eliminate a lot of duplicate script code or allow using PowerShell in scripting scenarios that previously required Python or Ruby.