πŸ‡―πŸ‡΅ ζ—₯本θͺž | πŸ‡ΊπŸ‡Έ English | πŸ‡ͺπŸ‡Έ EspaΓ±ol | πŸ‡΅πŸ‡Ή PortuguΓͺs | πŸ‡ΉπŸ‡­ ΰΉ„ΰΈ—ΰΈ’ | πŸ‡¨πŸ‡³ δΈ­ζ–‡

What is PowerShell? A Deep Dive into the Ultimate Shell Every Windows User Should Know

In our Bash introduction series so far, we've focused on the Bash shell, which is standard on macOS and Linux. However, many web creators out there are probably thinking, "But I use Windows for my daily work..." Don't worry! Windows comes standard with a super-powerful shell that far surpasses the old Command Prompt (the black screen). That's what we're introducing today: PowerShell.

PowerShell is more than just a command-line tool. It's like a "magic wand" that can automate all sorts of Windows settings and handle complex tasks with just a few lines of code. Its power is especially immense for managing servers in web development and for making daily tasks more efficient.

In this article, we'll answer beginner questions like "What is PowerShell?" and "How is it different from Command Prompt?" while explaining its basic usage and appeal with samples you can copy and paste to see them work. If you're a Windows user, you already have this ultimate weapon. Why not learn to master it starting today?


The Identity of PowerShell - The Ultimate Shell Born from Windows

PowerShell is a command-line shell and scripting language developed by Microsoft, specializing in the administration and automation of Windows. If the old Command Prompt is a calculator, then PowerShell is like Excel. Both can do calculations, but the types of data they can handle and the scope of what they can do are completely different.

The Biggest Difference is Handling "Objects"

The decisive difference between Command Prompt and PowerShell lies in the "format" of the information returned by commands.

This property of "handling objects" is what elevates PowerShell from a simple command-line tool to a powerful automation platform.


Experience the Power of PowerShell! Manipulating Objects with the Pipeline

The best way to understand is to see it in action rather than just reading an explanation. The true value of PowerShell is demonstrated when you chain commands together with the "pipeline |". Let's watch as objects are passed along a conveyor belt to the next command to be processed.

First, let's use the Get-Process command to get a list of all processes currently running on the computer. A feature of PowerShell commands is their easy-to-understand Verb-Noun format.

Get-Process

A lot of processes were displayed in a table format, right? This is a collection of objects.


Next, let's pass this result through a pipe to Where-Object to filter for only those where the "ProcessName is 'chrome'." The $_ refers to each individual object being passed through the pipe.

Get-Process | Where-Object { $_.ProcessName -eq 'chrome' }

Only the processes related to Chrome were displayed. Because it's an object, not text, you can easily filter by specifying a property like ProcessName.


Furthermore, let's pass the filtered result to Sort-Object to sort them in descending order of memory usage (WS).

Get-Process | Where-Object { $_.ProcessName -eq 'chrome' } | Sort-Object -Property WS -Descending

Just by chaining commands like this, you can perform complex data extraction and processing as if you were manipulating a database. This is the power of PowerShell.


Let's Try Some Basic Commands (Cmdlets)

PowerShell commands are officially called Cmdlets. Here, we'll introduce how to perform operations familiar from Bash or Command Prompt using PowerShell cmdlets. Many cmdlets have short "aliases" prepared, so you can still use familiar commands like ls and cd.

Changing Location (pwd, cd, sl)

Use Get-Location to check your current location, and Set-Location to move.

# Display the current location (alias: pwd)
Get-Location

# Move to the C:\Users directory (aliases: cd, sl)
Set-Location C:\Users

Listing Contents (ls, dir, gci)

Use Get-ChildItem to display a list of files and folders.

# Display the contents of the current directory (aliases: ls, dir, gci)
Get-ChildItem

Taking advantage of objects, it's also easy to recursively find only certain types of files (even inside subfolders).

# Search for all .css files from the current location downwards
Get-ChildItem -Recurse -Filter "*.css"

Creating Files and Folders (ni)

Use New-Item to create new items (files or folders).

Creating a file:

New-Item -Path ".\new-file.txt" -ItemType File

Creating a folder:

New-Item -Path ".\new-folder" -ItemType Directory

Reading and Writing File Content (cat, gc, sc)

Use Get-Content to read the contents of a file, and Set-Content to write to it.

Writing to a file:

"Hello from PowerShell!" | Set-Content -Path ".\new-file.txt"

Reading file content (aliases: cat, gc):

Get-Content -Path ".\new-file.txt"

Deleting Files and Folders (rm, del, rmdir)

Use Remove-Item to delete files and folders. This operation cannot be undone, so be very careful when executing it.

Remove-Item -Path ".\new-file.txt"

To delete a folder along with its contents, the -Recurse option is necessary.

Remove-Item -Path ".\new-folder" -Recurse

Conclusion

This time, we've provided an entry point into the world of PowerShell, the powerful shell that comes standard with Windows. You might be a bit confused by the unfamiliar cmdlets at first, but once you understand its essence, there's no tool more reliable.

In web development, it's common to work in a local Windows environment and deploy to a production Linux server. If you can master PowerShell to automate and streamline your work on Windows, and also handle a Linux environment seamlessly through WSL, you'll be unstoppable.

We hope today's article has given you a sense of PowerShell's charm and power. In the next article, we'll explain how to update this PowerShell to the latest version and the procedure for installing it on macOS/Linux.

[For Beginners] How to Install and Launch PowerShell (Windows / Mac / Linux)