PowerShell Administration Foundations
Learn what PowerShell is, how to start it, read cmdlet syntax, discover commands, use aliases, get help, and manage files and folders.
Content
What Is PowerShell
Versions:
Watch & Learn
What Is PowerShell — the Object Party in Your Terminal
PowerShell is what happens when a shell saw .NET, got emotionally attached to objects, and decided text-only pipelines were so last season.
You open a terminal hoping to type a single command and magically fix everything. Instead, you summon a hurricane of cryptic errors and a fan club for the word not recognized. Enter PowerShell: a cross-platform shell and scripting language that says, yes, you can automate that, and also, we speak fluent objects.
If you manage systems, wrangle servers, duct-tape cloud services, or just want your computer to behave like a well-trained dragon, understanding PowerShell is foundational. This is the Swiss Army flamethrower of admin tools.
The One-Sentence Vibe Check
PowerShell is a shell + scripting language + ecosystem, built on .NET, where the pipeline passes structured objects instead of raw text, making automation feel less like log-grepping and more like handling actual data.
Why you should care:
- It works on Windows, macOS, and Linux.
- It ships with thousands of cmdlets and can talk to almost anything: files, registry, services, Azure, AWS, VMware, REST APIs.
- It’s designed for admins, engineers, and anyone who is allergic to clicking through 47 dialog boxes.
History, But Make It Speedrun
- 2006: Windows PowerShell 1.0 launches (code name: Monad). Objects in the pipeline? Witchcraft.
- 2016+: PowerShell goes open source and cross-platform as PowerShell 6+ (now 7.x), built on modern .NET.
- Today: Windows PowerShell 5.1 still exists on Windows; PowerShell 7 runs side-by-side and is what you want for new scripts.
Rule of thumb: write new stuff in PowerShell 7; use 5.1 only when legacy Windows-only modules force your hand.
Shell vs Language vs Ecosystem
The Shell
- Interactive prompt with tab completion, history, and profiles.
- Pipeline connects commands with
|, but passes objects, not strings. - Aliases exist (
ls,cat,dir) but write scripts with real names for clarity.
The Language
- Strong but friendly typing: everything is a .NET object.
- Functions, modules, classes, exceptions, and all the cozy features of a modern language.
- Variables start with
$and arrays/hashes are built in.
The Ecosystem
- Cmdlets (pronounced command-lets) shipped by Microsoft and vendors.
- Modules add features: Az for Azure, PowerCLI for VMware, AWS.Tools, ActiveDirectory, and more.
- Providers expose weird places as drives: registry, certificates, environment variables.
The Big Idea: PowerShell Pipelines are Object-Oriented
Most shells: text flows through pipes like a never-ending string-nado.
PowerShell: structured .NET objects sail elegantly from command to command.
| Feature | Texty shells (e.g., bash) | PowerShell |
|---|---|---|
| Pipeline unit | Lines of text | Rich objects with properties and methods |
| Filtering | grep, awk, sed | Where-Object, Select-Object on real properties |
| Error handling | Exit codes, parse stderr | Exceptions, try/catch, -ErrorAction |
| Formatting | Same as data | Formatting is separate; data stays intact until you format |
Example:
# Top 5 CPU-hungry processes, cleanly
Get-Process |
Where-Object CPU -gt 100 |
Sort-Object CPU -Descending |
Select-Object -First 5 Name, CPU |
Format-Table -AutoSize
Pro tip: format at the end. Once you
Format-*, the pipeline becomes display-only; further data operations will have a bad day.
Speak the Language: Verb-Noun Cmdlets
PowerShell commands follow a strict Verb-Noun pattern: Get-Process, Set-ExecutionPolicy, Restart-Service.
- Discoverability is a feature:
Get-Commandshows what exists. - Standard verbs exist; check them with
Get-Verb. - Aliases are for typing speed, not for scripts.
Get-Command -Noun Service
Get-Help Restart-Service -Detailed
Get-Member -InputObject (Get-Process | Select-Object -First 1)
Motto: if you can discover it, you can automate it.
Providers and PSDrives: Admin Narnia
PowerShell treats certain data stores like file systems:
FileSystem: C:, /Users, etc.Registry:HKLM:andHKCU:Cert:certificate storeEnv:environment variables
Get-ChildItem HKLM:\Software\Microsoft | Select-Object -First 5
Get-ChildItem Env: | Sort-Object Name
No more weird custom tools just to peek at the registry; you can cd into it like it’s a folder. Delightful chaos.
Modules and Package Management
Add capabilities on demand.
# Install and import a module (requires admin sometimes)
Install-Module Az
Import-Module Az
Get-Module -ListAvailable | Sort-Object Name
PowerShell searches locations from $env:PSModulePath. Vendor ecosystems are massive; if it has an API, someone probably wrapped it.
Remoting: Commands That Travel
Run commands on other machines like a telepathic sysadmin.
- Windows Remoting uses WinRM; cross-platform can use SSH.
- Create a session, run commands, close the session.
# Run a command on remote computers
Invoke-Command -ComputerName server1, server2 -ScriptBlock { Get-Service Spooler }
# Enter an interactive remote session
Enter-PSSession -HostName ubuntu01 -User devops
Data over remoting is serialized objects. Same shape, fewer headaches.
Safety, Help, and Guardrails
-WhatIfpreviews changes;-Confirmasks for permission.-Verboseexplains what a cmdlet is doing.- Execution policy exists to prevent accidental script execution, not as a hardcore security boundary.
Restart-Service -Name Spooler -WhatIf
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
If you need real security, use code signing, constrained language mode, proper permissions, and good old threat modeling.
Everyday Mini-Recipes
Services
Get-Service | Where-Object Status -eq 'Stopped' | Select-Object -First 10 Name, Status
JSON (APIs love this)
$cfg = Get-Content ./config.json | ConvertFrom-Json
$cfg.FeatureFlags.NewUI = $true
$cfg | ConvertTo-Json -Depth 5 | Set-Content ./config.json
Processes (gently)
Get-Process | Where-Object Name -like 'chrome*' | Stop-Process -WhatIf
Events
Get-WinEvent -LogName System -MaxEvents 50 | Where-Object LevelDisplayName -eq 'Error'
Windows PowerShell vs PowerShell 7
- Windows PowerShell 5.1: built on .NET Framework, Windows-only, tons of legacy modules.
- PowerShell 7.x: cross-platform, faster, improved error handling, parallelism, and Predictive IntelliSense.
- They run side-by-side. For Windows-only modules that refuse to cooperate with 7, use compatibility shims or fall back to 5.1.
New projects: choose 7. Your future self will send thank-you fruit baskets.
Common Gotchas (aka How To Avoid Chaos)
- Running scripts: use
./script.ps1; the current directory is not in the path by default. - Single vs double quotes: single quotes are literal; double quotes expand variables.
- After
Format-Table, don’t try to sort or export; format at the end. - Arrays vs single objects: pipeline may hand you one or many. Coerce with
@()when you need an array. - Use the right filters early: filter left, format right.
Quick Mental Model
- Discover commands with
Get-CommandandGet-Help. - Inspect output with
Get-Memberto see properties. - Pipe into
Where-Object,Select-Object,Sort-Object,Group-Objectto shape data. - Export or act:
Export-Csv,ConvertTo-Json,Set-*,New-*,Remove-*.
Everything is an object. Stop parsing text; start asking objects for their properties.
Why People Misunderstand PowerShell
Because it looks like a terminal, they expect text. But PowerShell is secretly a .NET linter robot in a trench coat. Once you accept that it is data-first, not text-first, the entire experience clicks into place.
Wrap-Up: The Three-Command Challenge
Get-Help Get-Process -OnlineGet-Command *service*Get-Process | Get-Member
If you can do those three, you have the keys to the kingdom: find it, understand it, then automate it.
Key takeaways:
- PowerShell is a cross-platform automation shell that passes objects through the pipeline.
- Verb-Noun naming, rich help, and providers make it discoverable and admin-friendly.
- Use modules for superpowers; use remoting to scale.
- Format last, script in 7, and let objects do the heavy lifting.
Now go forth and automate. Your future 2 a.m. self will sleep better.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!