Evaluate Weigh the pros and cons of technologies, products and projects you are considering.

On Windows, PowerShell vs. Bash comparison gets interesting

Windows admins cottoning on to the CLI have a new option: integrated Bash, a Linux shell. But Bash doesn't stack up one-to-one with PowerShell for Windows deployments.

With Microsoft ushering Bash onto its systems, it's time to reevaluate Windows PowerShell vs. Bash.

Microsoft partnered with Linux vendor Canonical to port Bash to Windows in 2016. Bash integration with the Windows environment means that users can forgo dual-booting with Canonical's Ubuntu OS to get native Linux capabilities. Script-savvy Windows admins might wonder if Bash on Windows replaces PowerShell, which is similar to Unix and Linux systems and also already provides OpenSSH connectivity over the Secure Shell protocol.

Does Linux friendliness at Microsoft tip the scales in the Windows PowerShell vs. Bash debate? "Absolutely not," said Jeffrey Snover, inventor of PowerShell and a Microsoft Technical Fellow. PowerShell is here to stay, he said, so admins must understand the differences between Microsoft's native automation scripting platform and Bash.

Windows PowerShell vs. Bash

Purpose and scope. PowerShell is a configuration management tool that brings the capabilities of Linux command-line interface (CLI) control into the historically point-and-click Windows environment to efficiently manage Windows servers in virtual deployments. Administrators can manage Windows server workloads or host production Linux workloads and server applications via PowerShell.

Bash, on the other hand, is more suited for developer environments. It was introduced to complement and strengthen CLI-based interaction. With the addition of Bash to Windows, code that developers or infrastructure engineers wrote for Linux can work on their Windows systems, too. Picture Linux-first tools -- Python, Ruby, Git -- that are common in DevOps shops running directly on Windows.

Bash for Windows doesn't mean all Windows. It debuted with the Windows 10 Anniversary Update in two parts: the core subsystem and the package. The core subsystem offers Linux APIs on Windows and is an integral part of the Windows 10 Insider Builds. Canonical offers the optional package that brings CLI tools for Linux systems. While PowerShell runs on any Windows version, you need x64 Windows 10 Anniversary Update Build 14393 or later to install and run Bash.

Learn how to use the PowerShell pipeline with author Adam Bertram.

Syntax. PowerShell is not just a shell; it is a complete scripting environment. PowerShell invokes lightweight commands called cmdlets at runtime via automated scripts or APIs. While PowerShell does not call for them, old disk OS commands still work well. PowerShell uses aliases, which point old commands to the corresponding new ones. The Get-Alias cmdlet gives you a list of all aliases in PowerShell.

Figure 1 shows an example of two commands, Ls from Bash and dir from PowerShell. While they're two separate CLI concepts, the output is not wildly different.

PowerShell dir vs. Bash Ls
Figure 1. In this comparison of Windows PowerShell vs. Bash, the output for Bash's Ls command and PowerShell's dir command is similar.

PowerShell relies on an object pipeline. It pipes objects, passing along the output of one cmdlet as the input for another one. The same data can be manipulated with multiple cmdlets in sequence. By piping objects, PowerShell scripts share complex data, passing entire data structures between commands. Bash, on the other hand, passes output and input as plain text, which means it is easy for the user to move information to the next program.

PowerShell directory list
Figure 2. PowerShell output for a directory list shows objects and properties.

Figure 2 shows how a directory list displays in PowerShell. The output is in the form of file objects with properties, such as date created and size, listed beside the files. Bash output, by contrast, is in the form of a set of strings, which are the text representations of file names. The end result is especially important: The scripts you write take the data that is returned and pass it on to another function or use it to perform an action.

Capabilities. PowerShell is a configuration management tool. It enables you to edit the registry, manage Microsoft Azure cloud and Exchange email, or conduct Windows Management Instrumentation. The Bash shell and command language don't offer these capabilities in Windows. With it as a developer tool on Windows, however, users can code and build functions or services while working on the same files from both the Linux and Windows CLI.

PowerShell makes it easy to access registry values and file properties using a common syntax. Extensible markup language processing is also straightforward.

The value of PowerShell vs. Bash comes down to the user. If you're working on several Windows systems, Bash is of little use; you'll need PowerShell to write scripts. Bash doesn't allow you to access local Linux files with Windows apps. For example, you can't use Bash to open a Linux file on Windows Notepad. While Bash is great for managing text files in a scripting environment, everything is managed through APIs, not files. So, Bash is really only useful when you want to import Linux code to Windows machines and develop that code.

To manage Windows workloads, PowerShell is effective with its .NET and COM+ integration. There are many object-oriented and modular features installed with PowerShell that extend the functionality of the tool to manage Windows-centric tasks on Active Directory, Exchange Server and SQL Server. VMware is easily managed via PowerShell as well. The CLI has good tracing and debugging functions. Users have multiple integrated development environments to code and test programs.

PowerShell cannot compete with Bash on Linux. Bash boasts an ecosystem of tools built from the ground up with Linux in mind.

Windows PowerShell and Bash differences
This chart shows the differences between Windows PowerShell and Bash.

Admins' learning curve for PowerShell vs. Bash

PowerShell deals with a lot of scripting. If you're from a Unix/Linux background, this tool looks familiar. However, for Windows GUI adherents, there's a steep learning curve. For instance, PowerShell 4.0 runs 299 built-in cmdlets, and each cmdlet has multiple options. To complicate matters, you have to use the correct parameters.

Bash on Windows comes with less than 40 internal functions and around 100 helper programs. With a slimmer syntax, Bash is faster, but PowerShell has the advantage of a consistent syntax structure. If you're just starting out, it will take some time to thoroughly exploit PowerShell's reach. Users familiar with the tool deploy, manage and repair hundreds of systems from any remote location, automate runbooks and use C#-based PowerShell script files to automate repetitive tasks.

Next Steps

Is Windows Bash a security risk?

Cross-OS admins stock up on skills, tools

Microsoft patches Linux subsystem for Windows

This was last published in September 2017

Dig Deeper on Scripting, Scheduling and IT Orchestration

Join the conversation


Send me notifications when other members comment.

Please create a username to comment.

Will PowerShell drive Linux admins to take on Windows administration?
this article is stupid. of course powershell can manage registry keys and not bash. there's no registry in Linux!!! there's no azure in linux. I believe this article doesn't talk about the versatility of each shells and just talks about what powershell does in windows exclusive situations. How can you compare a feature that both can't have in common... I mean really.... powershell can edit registry keys... thank god there is no registry hell in linux XD

Each shell has been designed around each operating system. True. Of course, Bash can't manage the Windows registry natively but that's something people need to be reminded of if they decided to start using Bash on Windows. There are a lot of things Bash won't be able to do in Windows since it was built for Linux.
Glad I found this well-written article.  I am ... for grins ... since I am taking a few months off in semi-retirement) trying to use a Windows 10 Home OS and see what I can do (also using it as a client to my Ubuntu server).  So without the full bash in the Home OS ... I use gitbash.  Interestingly, I can also bring up bash in the powershell.  Seems like powershell could add support for some of the core linux commands that it does not currently support ... but that is me coming from my linux background.  I definitely see the value of each, but think it would be nice to bring them a little closer together.