Tech tips

PowerShell vs Command Prompt

PowerShell vs Command Prompt

PowerShell vs Command Prompt

In 2006 Microsoft released the PowerShell script environment often used by systems administrators. PowerShell was a dramatic enhancement over the traditional DOS Command Prompt that had been shipping with Windows up to that point. PowerShell introduced a host of features that brought it closer in line with what Linux users had been enjoying with terminal for years.

But many users still use the command prompt because of its simpler functionality and traditional commands users of the Windows operating system have come to expect.

Here’s what’s different about Powershell and Windows Command Prompt - and why Microsoft still ships both.

Command Prompt and Powershell Origins

Command prompt is a living relic of the computing world. Command prompt came out during the earliest days of computing back in 1987 when Microsoft came out with DOS. At that time both Unix and DOS were being developed. But Microsoft DOS, because of adoption from big players like IBM, became the computing standard.

Computers during the 80s didn’t have GUIs like today and the only way to move around a computer or mainframe was by using commands.

Once the graphical user interface (GUI) was invented, users had a new way to navigate their system, edit files, and perform basic tasks. However, even with the introduction of the GUI, the Command Prompt never went away. Power users and IT staff still used commands, especially when managing infrastructure.

PowerShell was introduced in 2006 and catered very much towards IT professionals and power users. PowerShell, unlike command prompt was based on .NET and emphasized scripting and automation to get tasks done. To this day PowerShell is still how many systems admins manage enterprise Windows environments.

Difference 1: CMD vs Cmdlet

The biggest difference between PowerShell and Command Prompt is that commands moved from being text to being scripts. Scripts allow users to perform tasks as simple as renaming a folder to installing a piece of software and all its dependencies.

When interacting with the command line, commands are text based and are generally based on a single word or set of letters to denote an action. For example, “CD” is change directory or go to a certain directory. To go to my documents I would type “cd documents". Command Prompt text commands are basic in nature and have little to no native ability to perform more than a single task at a time. Scripts and automation can be performed however but executing a .batch file within the Command Prompt.

PowerShell in contrast uses cmdlets which are self-contained scripts that allow users to perform actions. Cmdlets are two word that pair a capitalized verb and noun to indicate an action to perform on an object.

For example, Get-help denotes the user wants to access the object “help” which will display a set of PowerShell commands.

Cmdlets can also be created using .Net code by users.

A way Cmdlets are unique compared to commands is that they can be chained together and form a pipe. This allows a user to automate an action and perform several tasks with just a single cmdlet.

A useful feature Microsoft thought of to transition users over to PowerShell is that they have created command prompt style alias for many PowerShell commands that perform the same function. For example, CD can be used for Set-location which just like CD, allows users to move to a new directory.

Difference 2: PowerShell is Technically a Coding Language

PowerShell is based on .Net, allowing users to code their own scripts and objects. This is a massive departure from command prompt which is simply a way to navigate a system and perform basic actions.

The ability to code in PowerShell also allows users to create their own scripts that can run in PowerShell, limiting capabilities only to the users’ imagination.

Difference 3: PowerShell Can be Used on Linux

Though seemingly never taking off with the Linux crowd due to their arguably superior Terminal, PowerShell can function on both Windows and Linux.

PowerShell is very useful for organizations that work with both Linux and Windows environments. Organizations can create scripts and code that works across both environments relatively seamlessly.

Command prompt does not work with Linux at all. It is a legacy program from the DOS days. Many Windows functions can still be performed using command prompt, but it will unlikely see any adoption on Linux.

Difference 4: PowerShell Ushers in Objects

PowerShell is technically a coding language and it specializes in connecting different objects together into automations and scripts.

Objects are a complex topic that frankly only needs to be fully explored if you are a programmer. But for a regular user, objects are a set of parts that work together to “do something” For example, System.ServiceProcess.ServiceStartMode is an object.

Objects are also categorized by their “property” and “class”.

Properties: A description for what an object does. An object can have multiple properties. For example, a file object can have the property of being “isreadonly” like in this Microsoft example.

Class: Class is a very high level descriptor of what an object is. For example something could be a device. Microsoft has examples here.

PowerShell scripts power communication between objects in order to perform a function. A common example is creating a PowerShell script to connect involved objects to install an application or run code.

Command Prompt commands are text-based meaning that native automation isn’t possible. Instead, text-based commands allow the user to perform functions manually including navigation and execution of files.

The Line Between PowerShell and CMD is Now Blurred

Microsoft has made efforts over the years explain and simplify the confusing system of users having access to both PowerShell and Command Prompt. Progress started with allowing PowerShell users to execute .batch scripts and CMD commands in PowerShell. But CMD and PowerShell still existed as separate entities.

Microsoft has now released the new Microsoft Terminal which takes Terminal (Linux), PowerShell, and Command Prompt, and combines them all into one program. Users can now execute commands from all three within the same program.

Microsoft still ships PowerShell and Command Prompt in Windows. But over the next few Windows updates they will likely become completely phased out in favor of the more unified Microsoft Terminal.

Summary

PowerShell and CMD at first seem like redundant tools. But both serve completely different functions hence why they have been shipped together in Windows to this point. And even though CMD commands can be executed in PowerShell, there is an air of familiarity when executing simply legacy commands in the basic Command Prompt.

But with Microsoft’s efforts to combine both into a new Windows Terminal application, and the CMD aliases that can be performed in PowerShell via aliases, it seems the two will eventually merge.

The biggest questions arguably is will Microsoft abandon PowerShell because of Windows’ new capability to perform Linux commands?

Sign Up For Our Newsletter

Get featured blog articles, industry news, and specials straight in your inbox.