8.5 KiB
8.5 KiB
Windows PowerShell Guide & Cheat Sheet
A practical guide for new users learning Windows PowerShell.
This document covers:
- Basic PowerShell concepts
- Command discovery
- Navigation and file management
- Processes and services
- Networking commands
- Pipelines and filtering
- Script execution
- Best practices
- A quick reference cheat sheet
PowerShell is object-based, meaning commands return structured objects instead of plain text, making automation and filtering far more powerful than traditional shells.
Table of Contents
- 1. Getting Started
- 2. Discovering Commands
- 3. Navigation
- 4. Files and Folders
- 5. Processes
- 6. Services
- 7. System Information
- 8. Networking Commands
- 9. Event Logs
- 10. The PowerShell Pipeline
- 11. Filtering and Selecting Data
- 12. Script Execution
- 13. Basic Scripting
- 14. Useful Aliases
- 15. Troubleshooting Commands
- 16. Best Practices
- 17. Quick Cheat Sheet
1. Getting Started
Open PowerShell from the Start menu by searching PowerShell.
Run as Administrator when performing system tasks.
Check PowerShell Version
$PSVersionTable
Command Structure
PowerShell commands follow the format:
Verb-Noun
Examples:
Get-Process
Get-Service
Set-Location
New-Item
Remove-Item
2. Discovering Commands
Get help for a command
Get-Help Get-Service
Show examples
Get-Help Get-Service -Examples
Show detailed help
Get-Help Get-Service -Detailed
Update help files
Update-Help
Find commands
Get-Command *service*
Get-Command *event*
Inspect objects
Get-Service | Get-Member
3. Navigation
Current location
Get-Location
Change directory
Set-Location C:\Temp
cd C:\Temp
Go up a directory
cd ..
Home directory
cd ~
List files
Get-ChildItem
Aliases:
dir
ls
Show hidden files
Get-ChildItem -Force
Recursive listing
Get-ChildItem -Recurse
4. Files and Folders
Create folder
New-Item -Path C:\Temp\TestFolder -ItemType Directory
Create file
New-Item -Path C:\Temp\test.txt -ItemType File
Copy files
Copy-Item C:\Temp\file.txt C:\Backup\
Copy folder recursively
Copy-Item C:\Temp\Folder C:\Backup\ -Recurse
Move file
Move-Item C:\Temp\file.txt C:\Archive\
Rename
Rename-Item file.txt newfile.txt
Delete
Remove-Item file.txt
Delete folder
Remove-Item Folder -Recurse -Force
Read file
Get-Content file.txt
Tail logs
Get-Content log.txt -Tail 50
Watch logs
Get-Content log.txt -Wait
5. Processes
Get-Process
Get-Process notepad
Start-Process notepad
Stop-Process -Name notepad
Stop-Process -Id 1234 -Force
6. Services
Get-Service
Get-Service spooler
Start-Service spooler
Stop-Service spooler
Restart-Service spooler
7. System Information
Get-ComputerInfo
Get-CimInstance Win32_OperatingSystem
Get-CimInstance Win32_BIOS
Get-CimInstance Win32_ComputerSystem
Get-Disk
Get-Volume
8. Networking Commands
Get-NetIPAddress
Get-NetAdapter
Get-DnsClientServerAddress
Test-Connection google.com
Test-NetConnection google.com -Port 443
Resolve-DnsName google.com
9. Event Logs
Get-EventLog -List
Get-EventLog -LogName System -Newest 20
Get-WinEvent -LogName System -MaxEvents 20
Get-WinEvent -LogName System | Where-Object LevelDisplayName -eq "Error"
10. The PowerShell Pipeline
Get-Process | Sort-Object CPU -Descending
Get-Service | Where-Object Status -eq Running
Get-Process |
Select-Object Name, Id, CPU |
Export-Csv processes.csv -NoTypeInformation
11. Filtering and Selecting Data
Get-Service | Select-Object Name, Status
Get-Process | Where-Object CPU -gt 100
Get-Process | Sort-Object CPU -Descending
Get-Process | Select-Object -First 10
(Get-Service).Count
12. Script Execution
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
.\script.ps1
powershell.exe -ExecutionPolicy Bypass -File script.ps1
13. Basic Scripting
Variables
$name = "Server01"
If example
if ($name -eq "Server01") {
Write-Host "Match found"
}
Loop
$services = "spooler","w32time"
foreach ($service in $services) {
Get-Service $service
}
Function
function Get-ServiceStatus {
param ($Name)
Get-Service $Name
}
14. Useful Aliases
Alias Command
dir Get-ChildItem ls Get-ChildItem cd Set-Location pwd Get-Location cat Get-Content cp Copy-Item mv Move-Item rm Remove-Item ps Get-Process cls Clear-Host
Get-Alias
15. Troubleshooting Commands
Get-Service | Where-Object Status -eq Running
Get-Service |
Where-Object {
$_.StartType -eq "Automatic" -and $_.Status -ne "Running"
}
Get-Volume
Get-WinEvent -LogName System -MaxEvents 50
Get-NetTCPConnection -State Listen
Test-NetConnection server01 -Port 3389
16. Best Practices
Use full command names
Prefer:
Get-ChildItem
Instead of:
ls
Test dangerous commands
Remove-Item C:\Temp\OldLogs\* -WhatIf
Prefer CIM over WMI
Get-CimInstance Win32_OperatingSystem
Log sessions
Start-Transcript C:\Temp\powershell.log
Stop-Transcript
17. Quick Cheat Sheet
Navigation
Get-Location
Set-Location C:\Temp
Get-ChildItem
Files
New-Item -ItemType File test.txt
Copy-Item test.txt C:\Backup\
Remove-Item test.txt
Processes
Get-Process
Stop-Process notepad
Services
Get-Service
Restart-Service spooler
Networking
Get-NetIPAddress
Test-NetConnection google.com -Port 443
Resolve-DnsName google.com
Help
Get-Help Get-Service
Get-Command *network*
Get-Member
Recommended Learning Path
- Learn Get-Help
- Understand pipelines
- Learn Where-Object and Select-Object
- Practice system queries
- Start writing small scripts
- Automate real admin tasks
PowerShell becomes powerful when commands are combined into automation pipelines.