PowerShell vs CMD: Unlocking the Power of Windows
We explore the power of PowerShell and why it's a worthy successor to the command line interface
PowerShell was introduced as a more robust and feature-rich command-line shell to replace CMD.exe. It allows IT administrators to more efficiently, and more effectively, manage multiple users’ machines at once and can be used by remote support teams as well as in-house IT departments alike.
It’s a cross-platform automation tool that combines a scripting language with a command-line shell, enabling tasks such as process automation and machine configuration management within organisations. Microsoft PowerShell works across Windows, Linux, and macOS, and can also be used to manage machines in cloud environments such as Microsoft Azure.
CMD.exe is an example of a command-line interface (CLI), that was popular in the earlier days of Windows administration, but replacements were being conjured years before PowerShell’s release. Introduced in Windows NT circa 1993, CMD.exe was the successor to command.com but its replacement began development in 2002 with a project called Monad - the Microsoft Shell. After a series of beta releases, Monad was renamed 'Windows PowerShell' and launched years later in September 2006.
PowerShell and CMD.exe are still used in computing today, though not interchangeably. The capabilities of PowerShell far outweigh those of CMD.exe and includes more than 130 general command-line tools. Powershell is now the default command shell in Windows, taking CMD.exe’s mantle in 2017, with users able to access it through File Explorer.
So why the shift to PowerShell?
PowerShell is significantly more powerful and rich in capabilities compared to CMD.exe; it’s able to manage hundreds of machines across different platforms whereas CMD.exe is only capable of executing much simpler tasks on a smaller scale.
CMD.exe was never designed to handle such complex computing tasks, which is where PowerShell can step in. This platform can capably manage devices on the Azure cloud, handle the creation and monitoring of virtual machines (VMs), as well as configure cloud storage.
Jeffrey Snover, the head of the PowerShell project team, designed the tool as the missing link between Microsoft's GUI-based administrative tools and the rich set of application programming interfaces (APIs) that expose the company's .NET framework.
Snover was the author of the original Monad whitepaper from 2022 and said in a 2017 interview that the project was born out of a desire to bring UNIX tools to Windows, but core architectural differences proved too steep a stumbling block to achieve that goal.
He wanted a single command-line tool to support both developers and administrators. In this sense, PowerShell was one of the first forays into what became DevOps, a practice that promotes collaboration between developers and operations teams.
What can PowerShell do?
Unlike CMD.exe, PowerShell is an object-oriented tool. Objects are representations of items like files and directories that have their own properties and actions that you can call upon in the CLI. PowerShell understands everything in Windows as an object but also lets you create your own object types.
PowerShell enables admins to get at these objects using more sophisticated commands than you'll find in CMD.exe. One of the tool's key innovations is its use of commandlets (CMDlets). These are small programmes (as little as a dozen lines of code) that can carry out specific tasks using .NET's APIs. They can execute an object's methods, query and change its attributes, and return objects as their results.
CMDlets come in a simple verb-noun form and enable you to get things done quickly. For example, typing Get-Member gives you information about an object, like its properties or attributes.
Get-Member won't do much on its own, though. You need a pipeline, another thing that wasn't available in CMD.exe. Unix and Linux users have enjoyed pipelines for decades, and it's just one command that PowerShell supports from the Bash shell that's common to those systems.
A pipeline lets you take the output of one command and 'pipe' it to another, which takes it as input. You depict a pipeline using |. Say you want to create an object in PowerShell:
$message = Write-Output 'PowerShell is awesome'
You've just used the Write-Output CMDlet to assign some text to what many languages would call a variable. Except in PowerShell, it's not a variable; it's an object with its own methods and properties. You can list them all by piping the $message object to Get-Member:`$message | Get-Member'
You can pipe lots of CMDlets together to create extensive chains of commands, like a conveyor belt of workers adapting something and passing it on to the next person.
Piping aside, this kind of object-oriented programming will be familiar to developers who work with languages like Python. You can even make the object give up certain information about itself using the object's name, a dot, and the property name. For example: $message.Length returns 21
You can create CMDlets yourself in a variety of languages, including Microsoft's own C#. An alternative approach to creating your own PowerShell programmes is to write scripts, which are collections of PowerShell commands collected together into a file that you can run. Although cmd.exe also allows scripts, PowerShell provides its own interactive scripting environment (PowerShell ISE) with a range of extra features like Intellisense, which gives you context-aware method and property options as you're typing.
There's another thing PowerShell gives you that cmd.exe doesn't: the ability to create modules. These are packages of related scripts and/or CMDlets that call upon each other to help carry out a bigger task. You can share lots of complementary scripts and CMDlets far more easily as a module. Sharing is a big part of the PowerShell story. For example, there's a PowerShell gallery containing thousands of scripts and modules from developers.
PowerShell keeps evolving
In 2016, PowerShell was taken open source as PowerShell Core, and since then it has been ported over to Linux and macOS as an alternative to the common Bash shell. However, if you’re planning on installing PowerShell on something other than Windows, you’re also going to have to lift .NET Core (the open source equivalent to Windows .NET) onto the system too. It’s also important to keep in mind that some functionality won’t transfer over - for example, it won’t support the ISE scripting environment.
PowerShell has been updated and expanded upon over the years since, with new functionality and support for classes (objects that can be used as templates to create other objects), as well as integrations with things like Visual Studio Code - which is available for both the native Windows and open source versions.
So now you know its history and how it works, the question then becomes: Should you use it?
The learning curve might seem steep at first, but it’s actually easier to use than you might think. If you can get past that initial hump, then you’ll find that PowerShell offers some genuinely worthwhile features, even if you don’t use each one of them all the time. After all, it’s better to have a powerful toolbox with a set of tools you rarely use, than relying on a 20-year-old set of pliers.
Four strategies for building a hybrid workplace that works
All indications are that the future of work is hybrid, if it's not here alreadyFree webinar
The digital marketer’s guide to contextual insights and trends
How to use contextual intelligence to uncover new insights and inform strategiesFree Download
Ransomware and Microsoft 365 for business
What you need to know about reducing ransomware riskFree Download
Building a modern strategy for analytics and machine learning success
Turning into business valueFree Download