This cheat sheet gives you the most useful PowerShell commands with practical examples, covering file management, system info, processes, and more. You’ll get a clear command, a short explanation, and a real example you can copy and run. The goal is to make you productive in PowerShell quickly, whether you’re a beginner or an experienced admin.
Background: Why PowerShell Matters
PowerShell is a command-line shell and scripting language from Microsoft, built on the .NET framework. It’s designed for system administration and automation, and it’s the default shell on Windows. Unlike the old Command Prompt (cmd.exe), PowerShell works with objects, not just text. That means commands (called cmdlets) output structured data you can filter, sort, and pipe to other commands. This object‑oriented approach makes complex tasks like managing services, files, or the registry much easier and more reliable.
PowerShell is also cross‑platform: it runs on Windows, Linux, and macOS (as PowerShell Core, version 7+). Many IT pros use it to automate repetitive tasks, from renaming hundreds of files to deploying software across a network. Learning a few core commands can save hours of manual work.
How PowerShell Commands Work
PowerShell commands follow a verb‑noun naming convention, like Get-Process, Set-Location, or Copy-Item. The verb says what to do (Get, Set, Copy, Remove, Start, Stop), and the noun says what you’re working with (Process, Location, Item). This makes commands predictable and easy to guess.
A key feature is the pipeline: you can pass the output of one command to another using the pipe character |. For example, Get-Process | Sort-Object CPU -Descending gets all processes and sorts them by CPU usage. You can also filter with Where-Object and select specific properties with Select-Object.
Here are a few basic commands you’ll use constantly:
Get-Command– lists all available cmdlets, functions, and aliases.Get-Help– shows help for a command (e.g.,Get-Help Get-Process).Get-Alias– shows aliases likelsforGet-ChildItemandcdforSet-Location.
Essential File and Directory Commands
Managing files and folders is a daily task, and PowerShell has powerful cmdlets for it. Here are the ones you’ll use most:
Get-ChildItem– lists files and folders. Example:Get-ChildItem C:\Users\YourName\Documents. Use-Recurseto list subfolders too.Set-Location– changes the current directory. Example:Set-Location D:\Projects(or justcd D:\Projects).Copy-Item– copies files or folders. Example:Copy-Item file.txt C:\Backup\file.txt. Add-Recursefor folders.Move-Item– moves or renames. Example:Move-Item old.txt new.txt.Remove-Item– deletes files or folders. Example:Remove-Item temp.log. Be careful: it doesn’t go to the Recycle Bin by default.New-Item– creates a new file or folder. Example:New-Item -ItemType Directory -Path C:\NewFolder.Get-Content– reads a text file. Example:Get-Content config.txt. Add-Tail 10to see the last 10 lines.
These commands support wildcards, so Get-ChildItem *.txt lists all text files in the current folder.
System Information and Process Management
PowerShell is great for getting system details and controlling running processes. These commands are invaluable for troubleshooting and monitoring:
Get-Process– lists running processes. Example:Get-Process -Name chromeshows all Chrome processes. To stop a process, useStop-Process -Name chrome -Force.Get-Service– lists Windows services. Example:Get-Service | Where-Object {$_.Status -eq 'Running'}shows only running services. Start or stop withStart-ServiceandStop-Service.Get-WmiObjectorGet-CimInstance– gets system information. Example:Get-CimInstance Win32_Processorshows CPU details.Get-CimInstance Win32_OperatingSystemgives OS info.Get-Date– shows current date and time. You can format it:Get-Date -Format "yyyy-MM-dd".Get-Location– prints your current directory path.Get-History– shows commands you’ve typed in the current session.
For a quick system overview, try Get-ComputerInfo (Windows only) – it returns a large object with OS, RAM, and more.
Filtering, Sorting, and Formatting Output
Raw output can be overwhelming. PowerShell gives you tools to shape it:
Where-Object– filters objects based on a condition. Example:Get-Process | Where-Object {$_.WorkingSet64 -gt 100MB}lists processes using more than 100 MB of memory.Sort-Object– sorts by a property. Example:Get-Process | Sort-Object CPU -Descending.Select-Object– picks specific properties or the first N objects. Example:Get-Process | Select-Object -First 5 Name, CPU.Format-TableandFormat-List– control how output is displayed. Example:Get-Service | Format-Table Name, Status -AutoSize.Export-Csv– saves output to a CSV file. Example:Get-Process | Export-Csv processes.csv -NoTypeInformation.
These cmdlets are the heart of PowerShell’s power: you can chain them together to get exactly the data you need, fast.
Common Mistakes and How to Avoid Them
Even experienced users trip up on a few things. Here are the most common pitfalls:
- Forgetting the dollar sign in variables – In
Where-Object, you must use$_to refer to the current object. WritingWhere-Object {$_.Status -eq 'Running'}is correct;Where-Object {Status -eq 'Running'}fails. - Using cmd.exe commands that don’t work the same – For example,
dirworks as an alias forGet-ChildItem, butcopyis not the same asCopy-Item. Use the PowerShell cmdlets for consistency. - Not quoting paths with spaces – Always put paths in quotes, like
Copy-Item "C:\My Folder\file.txt" "D:\New Folder". - Deleting without a confirmation –
Remove-Itemdoesn’t ask for confirmation by default. Use-WhatIfto preview what would happen:Remove-Item *.log -WhatIf. - Mixing up
-eqand=– In PowerShell,-eqis for comparison,=is for assignment. So$a = 5sets a variable,$a -eq 5checks if it equals 5.
Safety and Best Practices
PowerShell is powerful, so a few safety habits are essential:
- Use
-WhatIfand-Confirm– Many destructive cmdlets support these.-WhatIfshows what would happen without doing it;-Confirmasks before each action. - Test in a sandbox – Before running a script on production systems, test it on a VM or a non‑critical machine.
- Understand execution policy – PowerShell may block scripts by default. You can check with
Get-ExecutionPolicy. To run a script, you might need to change the policy, but do so carefully (e.g.,Set-ExecutionPolicy RemoteSignedfor local scripts). - Be cautious with
Invoke-Expression– It executes a string as code. Avoid it unless you’re absolutely sure what’s in the string. - Run as administrator only when needed – Some commands (like installing modules or changing system settings) require elevated rights. Using an admin shell for everyday tasks increases risk.
Alternatives to PowerShell on Windows
PowerShell isn’t the only way to work with the command line on Windows. Here’s how it compares:
- Command Prompt (cmd.exe) – The legacy shell. It’s simpler but far less powerful. No object pipeline, no scripting language (batch files are limited). PowerShell is the recommended replacement.
- Windows Subsystem for Linux (WSL) – Lets you run Linux commands (bash, grep, awk) directly on Windows. Great for developers who need Unix tools. You can even call PowerShell from WSL and vice versa.
- Third‑party shells like Git Bash or Cygwin – Provide Unix‑style commands on Windows, but they don’t integrate as deeply with Windows system administration as PowerShell does.
For most Windows admin tasks, PowerShell is the best choice because it’s native, object‑oriented, and fully supported by Microsoft.
Frequently Asked Questions
How do I find the right PowerShell command?
Use Get-Command with a wildcard, like Get-Command *process* to find all commands related to processes. You can also use Get-Help on any command to see examples, like Get-Help Get-Process -Examples.
What’s the difference between Get-WmiObject and Get-CimInstance?
Get-CimInstance is the newer, recommended cmdlet. It uses the CIM standard and works better with remote machines and PowerShell Core. Get-WmiObject is legacy and may not be available in PowerShell 7+. Use Get-CimInstance for new scripts.
How can I see the last few lines of a log file?
Use Get-Content -Tail 20 to show the last 20 lines. For example: Get-Content C:\Logs\app.log -Tail 20. This is much faster than reading the whole file.
How do I run a PowerShell script?
Save your script as a .ps1 file, then run it by typing .\script.ps1 in the PowerShell window. If you get an execution policy error, you may need to change the policy or run Set-ExecutionPolicy RemoteSigned (as admin) first.
Can I use PowerShell on Linux or macOS?
Yes, PowerShell 7+ runs on Linux and macOS. You can install it via package managers like apt or brew. Most core cmdlets work the same, though some Windows‑specific ones (like Get-Service) may have limitations.
How do I output results to a file?
Use Out-File to save text output, or Export-Csv for structured data. Example: Get-Process | Out-File processes.txt or Get-Process | Export-Csv processes.csv -NoTypeInformation.