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.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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 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.
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.
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.
Is Windows Bash a security risk?
Cross-OS admins stock up on skills, tools
Microsoft patches Linux subsystem for Windows