PowerShell Fundamentals on Windows Server 2022
From your first cmdlet to your first working script. No prior scripting experience required.
Learning objectives
- Explain what PowerShell is and how it differs from Command Prompt
- Identify and run cmdlets using the Verb-Noun convention
- Use
Get-Help,Get-Command, andGet-Memberto teach yourself any cmdlet - Chain cmdlets together with the pipeline to filter, sort, and export data
- Configure an execution policy, then write, save, and run a
.ps1script - Automate a real administrative task: a server health report
How this lesson works
Use the navigation pane on the left (or the Next button below) to move through the modules in order. Modules 1–4 build vocabulary, Modules 5–8 build skills, and Modules 9–11 put them to work on real server tasks.
The Practice Terminal is a simulated Windows PowerShell console built into this lesson. You can type real cmdlets into it and get realistic output — without any risk to an actual server. Look for the "Try it in the Practice Terminal" links throughout the modules.
What Is PowerShell?
A command-line shell and a scripting language, purpose-built for Windows administration.
PowerShell is the primary administrative tool for Windows Server 2022. Some server tasks can only be performed in PowerShell, and on Server Core installations (servers with no desktop GUI) it is essentially your entire interface. Every hour you invest here pays back in every Windows course and every IT job that follows.
PowerShell vs. Command Prompt (cmd.exe)
| Command Prompt | PowerShell |
|---|---|
| Outputs plain text | Outputs objects with properties you can sort, filter, and export |
| Small set of built-in commands | Thousands of cmdlets — plus everything cmd can do |
| Batch files (.bat) with limited syntax | A full scripting language (.ps1) with variables, loops, and logic |
| Manages one machine at a time | Can manage hundreds of servers remotely at once |
Launching PowerShell on Server 2022
Windows Server 2022 ships with Windows PowerShell 5.1 installed. Three ways to open it:
- Start menu: right-click Start → Windows PowerShell (Admin)
- Run box: press Win + R, type
powershell, then press Ctrl + Shift + Enter (this shortcut launches it elevated) - Server Manager: Tools menu → Windows PowerShell
Verify your version
You also have the PowerShell ISE (Integrated Scripting Environment) pre-installed — a simple editor with a script pane on top and a console below. We'll use it in Module 7 to write our first script.
Cmdlet Anatomy: Verb-Noun
Every PowerShell command — called a cmdlet — follows the same predictable pattern.
Standard verbs
The verbs are standardized across all of PowerShell. Learn a handful and you can guess cmdlets you've never seen — and usually be right:
| Verb | Meaning | Example |
|---|---|---|
Get- | Retrieve information (safe, read-only) | Get-Process |
Set- | Change a setting | Set-Service |
New- | Create something | New-LocalUser |
Remove- | Delete something | Remove-Item |
Start- / Stop- / Restart- | Control something running | Restart-Service |
Test- | Check or verify | Test-Connection |
Get- cmdlets never change anything, so you can't break the server while exploring. Run these three in the Practice Terminal: Get-Date, Get-Process, Get-ServiceThe Three Discovery Cmdlets
Nobody memorizes thousands of cmdlets. Professionals memorize three that find everything else.
1. Get-Command — "What cmdlet does X?"
2. Get-Help — "How do I use this cmdlet?"
3. Get-Member — "What can I do with this output?"
Pipe any cmdlet's output into Get-Member to see every property and method its objects carry:
The Pipeline
The pipe symbol | feeds the objects from one cmdlet into the next. Read pipelines left to right, like a sentence.
The Big Four pipeline cmdlets
| Cmdlet | Job |
|---|---|
Where-Object | Filter — keep only objects matching a condition |
Sort-Object | Sort by any property |
Select-Object | Choose which properties (columns) or how many objects to keep |
Export-Csv | Send results to a file you can open in Excel |
Where-Object block, $_ means "the current object coming through the pipe." So $_.Status -eq 'Stopped' reads: "the current object's Status property equals Stopped." Comparison operators use dashes: -eq (equals), -ne (not equal), -gt / -lt (greater/less than), -like (wildcard match).Quick Lab 5.1 — Pipeline practice
- List only the services that are currently Running.
- Show the 5 processes using the most memory (the property is
WorkingSet). - Create a Reports folder with
New-Item -ItemType Directory -Path C:\Reports, then export all running services toC:\Reports\running-services.csv.
Reveal solutions
Variables
Variables start with a dollar sign. No type declaration needed — PowerShell figures it out.
Your First Script (.ps1)
A script is just a text file of the same commands you've been typing — saved with a .ps1 extension so you can run it again and again.
Step 1 — Execution policy
As a security measure, Windows Server blocks script execution by default. Check yours, then set it to RemoteSigned — the standard for administrators. It runs local scripts freely but requires downloaded scripts to be digitally signed:
Unrestricted or Bypass on a production server just to make errors go away. Execution policy exists to stop malicious scripts from running silently. RemoteSigned is the professional balance.Step 2 — Write the script
Open the PowerShell ISE (Start → type "ise") or Notepad, and type:
Step 3 — Save and run it
.\ ("in this folder") to run a script from the current directory. It's a deliberate safety feature — it prevents a malicious script named ping.ps1 from hijacking a command you meant to run.Adding Logic: Read-Host, If, ForEach
Three building blocks turn a list of commands into a real program.
Read-Host — get input from the user
If / Else — make decisions
ForEach — repeat for every item in a list
Real Server Admin Tasks
Each of these one-liners replaces several minutes of clicking through the GUI.
Capstone: Server Health Report Script
Combine everything — variables, cmdlets, the pipeline, if/else, foreach — into one useful tool. Build this in the ISE and save it as C:\Scripts\Get-ServerHealth.ps1.
$($s.Name) is a subexpression — when you need an object's property inside a double-quoted string, wrap it in $( ). Also, `n is a newline character (backtick, not apostrophe).Knowledge Check & Practice Exercises
All hands-on exercises can be completed in the Practice Terminal.
Knowledge check
- What naming convention do all cmdlets follow, and why does it help you guess commands you've never used?
- What is the key difference between PowerShell output and Command Prompt output?
- What does
$_represent inside aWhere-Objectscript block? - Why is
RemoteSignedthe recommended execution policy instead ofUnrestricted? - Which discovery cmdlet shows you the properties a service object has?
Exercise A — Cmdlet scavenger hunt
- Using only
Get-CommandandGet-Help, find the cmdlet that lists local user accounts. Run it. - Find a cmdlet with the verb
Test-that checks network connectivity. Use it on8.8.8.8.
Exercise B — Pipeline builder
- Build one pipeline that finds all services whose name starts with "W" (hint:
-like "W*"), sorts them by Status, and displays only the Name and Status columns. - Export the result to
C:\Reports\w-services.csv. (CreateC:\Reportsfirst if it doesn't exist.)
Reveal solution
Exercise C — Script it (graded, on your lab VM)
Write a script named New-LabUser.ps1 that:
- Uses
Read-Hostto ask for a username - Checks with an
ifstatement whether that local user already exists (hint:Get-LocalUserwith-ErrorAction SilentlyContinue) - If not, creates the user with
New-LocalUserand prints a green success message; if the user exists, prints a red warning instead - Includes at least three comment lines explaining what the script does
Get-Help about_Functions on your lab VM. PowerShell ships with its own textbook: Get-Help about_* lists every conceptual topic.Practice Terminal
A simulated Windows PowerShell 5.1 console. Type cmdlets below and press Enter — output is generated locally in your browser, so you can experiment freely.
Tips: press ↑/↓ for command history · press Tab to auto-complete a cmdlet name · type help to list everything this simulator supports.