PowerShell is the tool I reach for when something needs doing on more than one server, or needs doing again next month. Most of what I have written about it here started as a note to myself after solving something at work, which is why the posts are small and task-shaped rather than a tutorial series.
This page groups them by what you are actually trying to do. If you are new to PowerShell, the naming convention is the one thing worth understanding first: every cmdlet is Verb-Noun, so Get-Service retrieves services and New-Item creates something. Once that clicks, most of PowerShell becomes guessable.
Two companion guides cover the rest of the same ground: Windows Administration for building and joining the servers you are scripting against, and WSL for the Linux side of a Windows machine.
The Guides
🌱 Getting Started
📁 Files & Folders
📊 Working With CSVs
🛡️ Windows Firewall
⏱️ Automation & Services
📡 Networking & Logs
The Cmdlets Worth Knowing by Heart
| Cmdlet | What you use it for |
|---|---|
Get-Command | Find a cmdlet when you know roughly what it should be called. Supports wildcards. |
Get-Help <cmdlet> -Examples | The fastest way to remember syntax. Run Update-Help once so it is worth reading. |
Get-ChildItem | List files and folders. Aliased to ls and dir. |
New-Item | Create a file or folder. Add -Force for nested paths, but never on a file you want to keep. |
Test-Path | Check something exists before acting on it. The basis of every safe script. |
Get-Service | Check, start, stop and restart Windows services. |
Select-Object | Pick the properties you want, and calculated ones with @{Name=..;Expression=..}. |
Where-Object | Filter the pipeline. Filter as early as you can for speed. |
Sort-Object / Format-Table | Order the output, then make it readable. Format last, never mid-pipeline. |
Two Habits That Save You
Use -WhatIf before anything destructive. Most cmdlets that change or remove things support it, and it prints what would have happened without doing it. On a delete script running against a directory full of production files, that one switch is the difference between a tidy-up and an incident.
# see what it would do, before it does it
Get-ChildItem -Path "D:\Logs" -Filter *.log |
Where-Object LastWriteTime -lt (Get-Date).AddDays(-30) |
Remove-Item -WhatIf
Format at the end, never in the middle. Format-Table turns objects into display text, so anything piped after it has lost the properties it needed. Do your filtering and sorting first, and format last.
Frequently Asked Questions
Windows PowerShell 5.1 or PowerShell 7?
Both, in practice. 5.1 ships with Windows and is what you will find on every server, so scripts that need to run anywhere target it. PowerShell 7 is the cross-platform version you install separately, and it is better in almost every way for your own work. Check what you are on with $PSVersionTable.
Why will my .ps1 file not run?
Almost always the execution policy. Windows blocks scripts by default, which is a sensible setting that catches everyone once. The fix, and what the policy options actually mean, is covered in the execution policy post above.
Do I need to run PowerShell as Administrator?
Only for things that change the machine: services, firewall rules, most installs. Reading files, querying services and testing connectivity do not need it. Run elevated when the task needs it rather than by habit.
Can PowerShell manage SQL Server?
Yes. The SqlServer module gives you Invoke-Sqlcmd and a large set of database cmdlets, and it is how a lot of SQL Server automation gets built. That side of my writing now lives at sqldba.blog, where the scripts are documented one page each.
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide. A good few of them are PowerShell.
Leave a Reply