Top 10 PowerShell Commands to Learn First (Get-Process, Set-Location, etc.)
Congratulations on installing PowerShell! Your machine is now equipped with a modern, powerful shell environment to accelerate your web development. However, it's a common experience for everyone to sit in front of the black (or blue) screen and freeze up, thinking, "So, what do I actually type?"
Don't worry. Thanks to PowerShell's consistent Verb-Noun naming convention for its commands (cmdlets), they are very easy to learn and apply once you get the hang of it. In this article, we've carefully selected the top 10 most useful basic cmdlets from the many available that will be truly helpful for a web creator's daily tasks.
Just as a guitarist learns a few basic chords to start playing various songs, by mastering these 10 commands today, you'll be taking the first step toward freely managing Windows and handling file operations. Now, let's actually type in the commands and experience their power!
The Absolute Basics: Cmdlets for Navigation and Listing
First, let's cover the three essential cmdlets for basic terminal operations: "checking your current location," "moving," and "seeing what's inside." These will become your "eyes" and "feet" in the CUI world.
1. Get-Location (aliases: pwd, gl)
This checks the full path of the directory you are currently in. It serves the same role as pwd in Bash and is your lifeline when you get lost.
Get-Location
2. Set-Location (aliases: cd, sl, chdir)
This moves to a different directory. You can use it with exactly the same feel as Bash's cd. It's nice that the cd alias is provided, isn't it?
# Move to the 'work' folder on the C: drive
Set-Location C:\work
3. Get-ChildItem (aliases: ls, dir, gci)
This displays a list of files and folders in the current directory. It serves the same role as ls in Bash and dir in Command Prompt.
Get-ChildItem
This is where PowerShell's true value begins. By using the -Recurse option, you can recursively display all items, even those inside subfolders.
# Display everything, including contents of subfolders
Get-ChildItem -Recurse
File Operations: Cmdlets for Creating, Viewing, and Deleting
Next, let's look at the cmdlets for directly manipulating files and folders. These will become your "hands."
4. New-Item (alias: ni)
This creates new files or folders. You specify which one to create with -ItemType.
Creating an empty file:
New-Item -Path ".\style.css" -ItemType File
Creating a new folder:
New-Item -Path ".\assets" -ItemType Directory
5. Get-Content (aliases: cat, gc, type)
This displays the contents of a text file. It's useful when you want to quickly check the contents of a configuration file.
Get-Content -Path ".\style.css"
6. Remove-Item (aliases: rm, del, erase, rmdir)
This deletes files and folders. [IMPORTANT] This command permanently deletes files immediately without moving them to the Recycle Bin. It cannot be undone, so please use it with extreme caution.
Remove-Item -Path ".\style.css"
The Essence of PowerShell: Cmdlets for Handling Objects
This is where PowerShell really shines. We'll introduce cmdlets that retrieve system status and information as "objects" and allow you to process them freely.
7. Get-Process (alias: ps)
This retrieves a list of currently running processes (programs) as objects. It includes detailed information such as CPU and memory usage.
Get-Process
8. Where-Object (aliases: where, ?)
This filters the objects passed from the pipeline | based on specified criteria. It functions like the WHERE clause in SQL.
For example, let's extract only the Google Chrome processes from all running processes.
Get-Process | Where-Object { $_.ProcessName -eq "chrome" }
9. Sort-Object (alias: sort)
This sorts objects by the value of a specified property (attribute).
Let's sort the Chrome processes from the previous example by memory usage in descending order.
Get-Process | Where-Object { $_.ProcessName -eq "chrome" } | Sort-Object -Property WS -Descending
10. Get-Help (aliases: help, man)
This is the last one we'll introduce, but it might actually be the most important command. Get-Help is your personal tutor that teaches you how to use other cmdlets. If you don't know how to use a command, try this first.
Get-Help Get-Process
By adding the -Examples option, you can see specific usage examples.
Get-Help Get-Process -Examples
Conclusion
Great work! This time, we introduced 10 basic cmdlets that will be your first weapons for exploring the world of PowerShell. While each one is simple, we hope you've felt how they can accomplish surprisingly complex tasks when chained together with the pipeline.
The trick to learning is to memorize the full Verb-Noun names, not just the aliases. If you do that, you'll be able to guess unknown commandsโ"I want to get X, so it's probably `Get-X`"โand your learning will accelerate rapidly.
Now that you've mastered the basic commands, the next step is to combine this knowledge to create your own automation tools, in other words, "PowerShell scripts." In the next article, we'll explain how to write a simple file operation automation script from scratch. Stay tuned!
Let's Automate File Operations with PowerShell! A Super-Beginner's Scripting Guide