Click any item to expand the explanation and examples.
📁 Navigation & Files
Get-ChildItem / Set-Location (ls, cd) files
Get-ChildItem # List files (alias: ls, dir)
Get-ChildItem -Recurse # Recursive
Get-ChildItem *.log # Filter by extension
Set-Location C:\Projects # Change directory (alias: cd)
Get-Location # Current directory (alias: pwd)
File operations files
New-Item -Path file.txt -ItemType File
New-Item -Path mydir -ItemType Directory
Copy-Item file.txt backup.txt
Move-Item file.txt archive/
Remove-Item file.txt
Remove-Item mydir -Recurse -Force
Get-Content file.txt # Read file (alias: cat)
Set-Content file.txt "Hello" # Write file
Add-Content file.txt "More text" # Append
Test-Path file.txt # Check if exists
🔍 Search & Filter
Select-String / Where-Object search
# Search in files (like grep)
Select-String -Path *.log -Pattern "error"
Select-String -Path *.cs -Pattern "TODO" -Recurse
# Filter objects
Get-Process | Where-Object { $_.CPU -gt 100 }
Get-ChildItem | Where-Object { $_.Length -gt 1MB }
Get-Service | Where-Object Status -eq "Running"
Pipeline and formatting pipeline
# Select specific properties
Get-Process | Select-Object Name, CPU, Id | Sort-Object CPU -Descending
# First/last N
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
# Format output
Get-Process | Format-Table Name, CPU, Id -AutoSize
Get-Process | Format-List *
# Count
(Get-ChildItem *.log).Count
# Export
Get-Process | Export-Csv processes.csv
Get-Process | ConvertTo-Json | Set-Content processes.json
⚙️ System & Processes
Processes and services system
Get-Process # List processes
Get-Process -Name "node" # Find specific
Stop-Process -Name "node" # Kill by name
Stop-Process -Id 1234 # Kill by PID
Get-Service # List services
Start-Service -Name "wuauserv" # Start service
Stop-Service -Name "wuauserv" # Stop service
Restart-Service -Name "wuauserv" # Restart
Environment variables system
$env:PATH # Read
$env:MY_VAR = "value" # Set (session only)
[Environment]::SetEnvironmentVariable("MY_VAR", "value", "User") # Permanent
Get-ChildItem Env: # List all
📜 Scripting
Variables, loops, functions script
# Variables
$name = "Alice"
$count = 42
$items = @("a", "b", "c")
$hash = @{ Name = "Alice"; Age = 30 }
# If/else
if ($count -gt 10) { "Big" } else { "Small" }
# Loops
foreach ($item in $items) { Write-Output $item }
1..10 | ForEach-Object { $_ * 2 }
while ($true) { Start-Sleep 1; break }
# Functions
function Get-Greeting($name) {
return "Hello, $name!"
}
Get-Greeting "Alice"
Error handling script
try {
Get-Content "missing.txt" -ErrorAction Stop
} catch {
Write-Error "Failed: $_"
} finally {
Write-Output "Cleanup"
}
See also: Bash cheat sheet | Linux Terminal cheat sheet