🇯🇵 日本語 | 🇺🇸 English | 🇪🇸 Español | 🇵🇹 Português | 🇹🇭 ไทย | 🇨🇳 中文

Let's Compare and Understand the Differences Between PowerShell and cmd [With Diagrams]

In the series so far, we've learned about the history of the traditional Windows shell, Command Prompt (cmd.exe), its basic usage, and even simple automation. Its simplicity and its continued existence for compatibility reasons could be said to be the history of Windows itself.

However, we also know of the existence of the more modern and powerful "PowerShell." Many of you are probably feeling, "I get the basics of cmd, but should I really switch to PowerShell?" or "I want to know more about the specific benefits."

This article is your "graduation guide." While fondly looking back at the "yearbook" that is Command Prompt, we'll thoroughly explain the decisive and concrete reasons why modern web creators should advance to the "new stage" पुलिस PowerShell, through comparison. By the time you finish reading this article, your hand opening the terminal will naturally be heading for the PowerShell icon.


Comparison 1: The Power to "Find" Information You Want - The Limits of Text and the Potential of Objects

The most fundamental difference between the two lies in the format of the information returned by commands. Understanding this is the key to understanding the difference between them.

Challenge: "I want to find the TOP 5 largest files in my documents folder."

An Attempt in Command Prompt (cmd)

Trying to do this in cmd is not straightforward. You can get a list of files with dir /s, but the result is just a string of text. Extracting only the file size part from this, sorting it correctly as a number, and displaying the top 5 items... this becomes a highly advanced and error-prone task that requires the use of complex for /f loops and string manipulation.

In other words, cmd is good for "humans to look at and judge," but it's not suited for "a program to reuse the results for more advanced processing."

The Brilliant Solution in PowerShell

On the other hand, in PowerShell, this task can be solved with a single, smooth line, like flowing water.

Get-ChildItem -Path "C:\Users\YourName\Documents" -File -Recurse | Sort-Object -Property Length -Descending | Select-Object -First 5

Here's what this one line is doing, step by step:

  1. Get-ChildItem: First, it gets all the files and folders in the specified folder as "objects."
  2. |: It passes the collection of objects to the next command via a pipe.
  3. Sort-Object: It sorts the passed objects by file size (the Length property) in descending order (-Descending).
  4. |: It passes the sorted results to the next command.
  5. Select-Object: From the passed objects, it selects and displays only the first 5 (-First 5).

Instead of struggling to parse text, you freely manipulate structured data by its properties. This is the biggest reason why PowerShell is said to be "powerful."


Comparison 2: The Power of "Integration" with the Outside World - To API or Not to API

In modern web development, it's common to retrieve and use data from external APIs (Application Programming Interfaces). For example, getting information from a web service or fetching weather forecast data.

Challenge: "I want to use the GitHub API to get Microsoft's user information and display the number of public repositories."

The Challenge in Command Prompt (cmd)

cmd has no built-in functionality to access the web and retrieve or parse data like JSON. To achieve this, you would need to separately install an external tool like curl, and then process the retrieved JSON text using yet another method, which is very cumbersome.

The Simple Solution in PowerShell

PowerShell comes standard with a powerful cmdlet called Invoke-RestMethod. It's an excellent tool that accesses a web API and automatically converts the returned JSON data into PowerShell objects.

First, let's get the data from the API and store it in a variable.

$gitHubUser = Invoke-RestMethod -Uri "https://api.github.com/users/microsoft"

And with just that, all that's left is to access the properties of the object.

Write-Host "Username: $($gitHubUser.name)"
Write-Host "Public Repositories: $($gitHubUser.public_repos)"

It's as if you were accessing local data, you can easily access web information with forms like .name and .public_repos. This ability to integrate with external services is an overwhelming advantage of PowerShell that cmd does not have.


Conclusion: Why We Should Graduate from cmd

As we've seen, PowerShell is not merely a successor to the Command Prompt. It is a completely new tool with a new philosophy, redesigned from the ground up to perform modern tasks.

The reasons why you should migrate from cmd to PowerShell are clear.

Knowledge of the Command Prompt is by no means wasted in understanding the history of Windows. However, to increase productivity as a web creator or an IT professional from now on, migrating to the more powerful and modern tool, PowerShell, is arguably the wisest investment.

This concludes our cmd.exe introduction series. We hope this series has helped you overcome your aversion to the "black screen" and discover the true power of the command line. Thank you!