Last updated: February 1, 2026
A practical introduction and daily reference for PowerShell beginners.
What is PowerShell? • Install • Cmdlets • File System • Objects • Variables • Scripts • Control Flow • Functions • Error Handling • Modules • External Systems • Best Practices • Tools • Cheat Sheet
PowerShell is a cross-platform automation and configuration shell built by Microsoft. It combines:
- An interactive command-line interface
- A powerful scripting language
- Deep integration with .NET, Windows, Azure, and modern APIs
PowerShell is designed for automation, system management, and repeatable workflows across Windows, Linux, and macOS.
Windows / macOS / Linux
- Go to the official release page: https://github.com/PowerShell/PowerShell/releases
- Download the latest stable installer for your OS.
- Install normally.
Running PowerShell
| Platform | How to Launch |
|---|---|
| Windows | Search PowerShell in Start Menu. Use PowerShell (Core) or Windows PowerShell (legacy). |
| macOS | Open Terminal → pwsh |
| Linux | Open your shell → pwsh |
Tip: Prefer PowerShell (Core) for modern scripting.
PowerShell commands are called cmdlets (pronounced "command-lets"). They follow a simple naming pattern:
Verb-Noun
Examples
Get-ProcessSet-LocationNew-ItemRemove-ItemGet-ChildItem
Discovering Cmdlets
Get-Command
Get-Command -Name *service*Getting Help
Get-Help Get-Process
Get-Help Get-Process -Examples
Update-HelpPowerShell treats the file system like a drive.
| Action | Command | Example |
|---|---|---|
| Change directory | Set-Location / cd |
cd C:\Scripts |
| List items | Get-ChildItem / ls |
ls /var/log |
| Show current directory | Get-Location / pwd |
pwd |
Examples
Set-Location C:\Users
Get-ChildItem -RecurseUnlike shells that return plain text, PowerShell returns objects.
Get-Process | Select-Object Name, CPU, IdYou can pipe objects between cmdlets to filter, sort, or transform them.
Common Object Cmdlets
Select-ObjectSort-ObjectWhere-ObjectFormat-TableFormat-List
Example Pipeline
Get-Process |
Where-Object { $_.CPU -gt 1 } |
Sort-Object CPU -Descending |
Format-Table -AutoSize$name = "Randy"
$count = 5
$items = @(1,2,3)$name.GetType()Use $null for empty or missing values.
PowerShell scripts have the .ps1 extension.
Running a Script
.\myscript.ps1Execution Policy
If your system blocks script execution:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUserif ($value -gt 10) {
"High"
} elseif ($value -gt 5) {
"Medium"
} else {
"Low"
}Foreach Loop
foreach ($i in 1..5) {
Write-Output "Number: $i"
}While Loop
while ($x -lt 10) {
$x++
}Functions make your code reusable.
function Get-Greeting {
param(
[string]$Name
)
"Hello, $Name!"
}Call it:
Get-Greeting -Name "Randy"try {
Get-Item "C:\does-not-exist.txt"
}
catch {
Write-Error "File not found!"
}throw "Something went wrong"Modules extend PowerShell's capabilities.
Get-Module -ListAvailableInstall-Module Az
Import-Module AzPowerShell integrates easily with REST APIs, cloud platforms, and services.
Example: Calling a REST API
Invoke-RestMethod -Uri "https://api.github.com/repos/PowerShell/PowerShell"- Use Verb-Noun naming for functions.
- Validate inputs (
[int],[string], etc.). - Comment your code for readability.
- Avoid hardcoding passwords or secrets.
- Prefer
Write-OutputoverWrite-Host. - Keep scripts idempotent (safe to run multiple times).
- Organize related functions into modules.
- Use consistent indentation and formatting.
- VS Code with the PowerShell extension
- Git + GitHub for source control
- PSScriptAnalyzer for code quality
- PowerShell Gallery (https://www.powershellgallery.com/) for modules
| Purpose | Cmdlet |
|---|---|
| Find commands | Get-Command |
| Get help | Get-Help |
| List files | Get-ChildItem |
| Copy file | Copy-Item |
| Move file | Move-Item |
| Delete file | Remove-Item |
| Check services | Get-Service |
| Stop process | Stop-Process |
ls # Get-ChildItem
cd # Set-Location
pwd # Get-LocationFor deeper learning, see the official docs: https://learn.microsoft.com/powershell