Technology / System Admin

Why PowerShell is Better than Bash

Why PowerShell is Better than Bash picture: A
Follow us
Published on August 12, 2021

It's no secret that PowerShell is often considered the inferior command-line environment compared to Bash, but why? Let's take a look at why PowerShell is better than Bash (at least in some ways) — and why comparing PowerShell to Bash is like comparing apples to oranges.

Why Do People Not Like PowerShell?

When you hear someone compare PowerShell to Bash and they say that Bash is the better command-line environment, they often don't fully understand the differences between both.

The PowerShell vs. Bash argument stems from the old days of computer management. Before PowerShell was introduced, IT professionals were stuck using the CMD app in Windows. The CMD app has deep roots in DOS (an old OS based around the command-line). CMD has the same functionality as DOS, but it was never really updated with new features.

Bash, on the other hand, has always been feature-rich. Bash started its life with tons of capabilities. Bash is also built around the basis of using small Linux applications to perform tasks, so it is easily expandable.

When PowerShell was introduced, it created a new paradigm in computer management and configuration. PowerShell is built around using .NET at its core, so it was originally only available for Windows. Until more recently, both .NET and PowerShell were not available for Linux. Because PowerShell is built around .Net, though, it has direct access to native Windows components and functions. This meant that PowerShell works in a fundamentally different way than Bash.

That's where the confusion lies. Both PowerShell and Linux are different tools for different jobs due to how they work and interact with the operating system. So, let's go over some of those fundamental differences and explain why PowerShell is better than Bash.

Data as Objects

One of the biggest differences between PowerShell and Bash is how both treat data. Bash treats data as simple strings while PowerShell treats data as objects.

Why is this so important?

Many web platforms use data objects for their APIs. These data objects can come in various forms like XML or JSON. For example, if you wanted to use the AWS SDK from Amazon to store a file in S3, you need to create a data object that stores information like the file name, where that file is found on the file system to transfer it, which AWS S3 bucket that file needs to be transferred to, that file's permissions, etc…

With PowerShell, you can create an object that stores that data. Then you can use the AWS SDK to transfer that file to S3 using that data object.

You couldn't do this with Bash. In Bash, that data object would be a simple string. You would need to pipe that string into a processor that could parse that information, turn it into an object, and then upload that file to your S3 bucket.

Because PowerShell can handle data as objects, certain tasks like machine configuration or communicating with APIs can be much easier without the need for help with other applications.

Cross-Platform

Originally PowerShell was only available on Windows. During the days of Bill Gates and Steve Balmer management, Microsoft was fiercely anti-Linux (or other operating systems for that matter). Since Satya Nadella took over the CEO position, Microsoft has changed priorities from focusing on Windows as its platform of choice to Azure. That means Microsoft needed to embrace Linux and Unix.

Microsoft embracing other platforms meant that their business practices shifted dramatically. With that shift, Microsoft made some parts of .NET open source. Because .NET was made open source, that meant other traditionally Windows-only tools, like PowerShell, could be made for other OS platforms, too.

And, that is exactly what happened. In 2016 Microsoft released the first open-source version of PowerShell for Linux. For the first time, PowerShell could be used both on Linux and Windows.

Bash is available on Linux, but it requires users to jump through a few hurdles before it can be used. For example, WSL needs to be enabled in Windows first. Then a Linux distribution needs to be installed and configured. Once those steps are completed, Bash can be used on Windows, though it does come with some added headaches still. For instance, Linux within WSL can be sandboxed to a certain degree, and Bash can't access all of the same Windows components and features that PowerShell can.

That isn't to say that PowerShell doesn't have issues with Linux, either. Because PowerShell is based on .NET at its core, it won't have access to all of the same commandlets on Linux as it does on Windows. Microsoft is working on including more commandlets for the open-source version of PowerShell, but it will never have the same functionality that the Windows version of PowerShell does on Linux, unfortunately.

Scripting

PowerShell is a true scripting language. You can create scripts in Bash, but those scripts are typically rudimentary instruction sets that explain how to carry out a task in the terminal. A script in Bash isn't very different from entering a bunch of commands manually. Those scripts still depend on piping data (or strings) between different applications.

On the other hand, PowerShell is a full scripting language like Python or JavaScript. You can create functions, declare variables, create data objects, etc… within PowerShell scripts. This opens a world of options for both Windows and Linux. Anything that you might want to automate with Python, you could potentially use PowerShell for instead.

Which CLI is right for me?

At the end of the day, comparing PowerShell to Bash is like comparing apples to oranges. Both are tools for different jobs.

If you are managing a Windows environment or using Azure, try sticking with PowerShell.

If you are managing a strictly Linux or Unix environment, try sticking with Bash.

If you are managing a mixed environment, it would be worthwhile to try using PowerShell for as much of your workload as possible. Using a single scripting language and environment will make managing those scripts much easier.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522