Fotolia

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

On Windows, PowerShell vs. Bash comparison gets interesting

Windows admins have the option to use Bash, a Linux shell, but the command-line tool doesn't stack up one-to-one with PowerShell for Windows deployments.

Updates to the Windows Subsystem for Linux, along with PowerShell Core, are set to shake up PowerShell vs. Bash comparisons.

Microsoft partnered with Linux vendor Canonical Ltd. to port Bash (Bourne Again Shell) to Windows in 2016. Bash integration with the Windows environment enables users to 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.

Windows Subsystem for Linux (WSL) has been around for several years, and developers have adopted it rapidly. Improvements to WSL make it easier to install multiple Linux distributions as necessary, support Linux line endings in Notepad and launch a Linux shell from File Explorer. In the past, admins could install Cygwin Bash to use the shell within Windows, but that did not offer a native Bash experience or proper integration with Windows. As such, WSL offers the best of both worlds and provides an improved experience.

Windows 10 version 1903 further enhances and expands WSL, with the ability, as one example, to navigate the Linux file system within File Explorer. These updates are part of WSL 2, an updated WSL architecture with a real Linux kernel that runs within Windows. WSL 2 enables full system call compatibility, so not only are WSL and Windows tightly integrated, but system performance is higher, as well.

Differences between Bash and PowerShell

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 manage Windows servers efficiently 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 traditionally suited for development environments. It was introduced to complement and strengthen CLI-based interaction. With the addition of Bash to Windows, code that developers or infrastructure engineers write for Linux works on their Windows systems, too. Picture Linux-first tools -- Python, Ruby, Git -- that are common in DevOps shops running directly on Windows.

Syntax. PowerShell is not just a shell; it is a complete scripting environment. PowerShell invokes lightweight commands called cmdlets at run-time 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.

PowerShell dir output
Figure 1. Output from dir in PowerShell

The commands ls -la in Bash and dir in PowerShell are two separate CLI concepts, but the output is not wildly different. Figure 1 shows the output of PowerShell dir commands, and 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.

By contrast, the Bash output in Figure 2 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.

Bash output
Figure 2. Output from ls -la in Bash

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.

The PowerShell output in Figure 3 demonstrates how one directory entry contains a wealth of properties. Use the command Get-ChildItem | Select-Object * -First 1 to show the many available properties on a single file-system object.

PowerShell output
Figure 3. Output from Get-ChildItem | Select-Object * -First 1

Capabilities. PowerShell enables admins 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. 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. XML 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. Admins can't access local Linux files with Windows apps -- such as Windows Notepad -- via Bash.

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

While Bash is great to manage text files in a scripting environment, everything is managed through APIs, not files. So, Bash is useful primarily to import Linux code to Windows machines and develop that code.

To manage Windows workloads, PowerShell is effective with its .NET framework 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 managed easily via PowerShell as well. The CLI has good tracing and debugging functions. Users have multiple integrated development environments to code and test programs.

PowerShell and Bash commands
Differences between PowerShell and Bash commands

Formerly, PowerShell could not compete with Bash on Linux. Bash boasts an ecosystem of tools built from the ground up with Linux in mind. With the advent of PowerShell Core, however, all of that has changed. PowerShell can run as a primary shell within Linux that contains all of the object properties for which PowerShell is famous.

Admins' learning curve for PowerShell vs. Bash

The value of PowerShell vs. Bash comes down to the user.

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. PowerShell Core, currently at version 6 and nearing version 7 at the time of updated publication, contains hundreds of cmdlets, each with a variety of parameters and the unique ability to run on different OSes.

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

Dig Deeper on Scripting, Scheduling and IT Orchestration

Join the conversation

5 comments

Send me notifications when other members comment.

Please create a username to comment.

Will PowerShell drive Linux admins to take on Windows administration?
Cancel
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

Cancel
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.
Cancel
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.
Cancel
the article is full biased, sided, partisan and full of joke
Cancel

-ADS BY GOOGLE

SearchDataCenter

SearchAWS

SearchServerVirtualization

TheServerSide.com

SearchCloudComputing

Close