PowerShell basics for Windows Server admins
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Core administration and security
-
Phase 3: Enterprise infrastructure
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
You’ve already used a dozen PowerShell commands by copying them, and now it’s time to understand them properly. PowerShell for Windows Server is the skill every later lesson leans on, and it’s the difference between an admin who clicks through fifty servers and one who fixes all fifty in one go.
First you’ll see how commands are named so you can guess them, where to find help, and the big idea behind PowerShell, which is that it passes objects rather than text. After that you’ll filter, sort and export real information from DC01 and write your first small script.
| Time | You need | By the end you can |
|---|---|---|
| About 60 minutes | DC01 from Lesson 6 (or your own laptop; almost everything works there too) | Find commands with Get-Command, read help, inspect objects with Get-Member, filter, sort and select with the pipeline, export to CSV, and run a small script safely |
What it is, in one line
PowerShell for Windows Server is Microsoft’s command shell and scripting language for managing servers, in which commands hand structured objects to each other through a pipeline.
In Simple Words
Passing a tray, not a note
Picture a kitchen where cooks pass dishes down a line. In the old kitchen, each cook writes a note about the dish and passes the note along (“plate with rice, curry on the left, about warm”), and the next cook has to read it and guess.
In a PowerShell kitchen the cooks pass the actual tray, so the next one can pick up the curry, check how hot it is and weigh it, because the real dish is sitting right there.
Old command-line tools pass text that you have to cut up and guess at, while PowerShell passes objects, so a service arrives as a real service with a Name, a Status and a StartType you can use straight away.
Engineer's View
Commands, help, objects and the pipeline
Verb-Noun names. Each cmdlet is named Verb-Noun, like Get-Service, Restart-Service, Set-TimeZone and New-NetIPAddress.
The verbs come from an approved list (Get, Set, New, Remove, Start, Stop, Test and others), so if you know the noun you can usually guess the rest, and Get-Command searches by verb, noun or wildcard.
Help is built in. Get-Help Get-Service -Examples shows working examples. Servers ship with only a short version of help, so run Update-Help once as administrator to download the full files.
Objects. Whatever a command returns is an object, with properties (data) and methods (actions).
Get-Member lists them for you. What you see on screen is just a default view of a few properties, and the object usually has many more.
The pipeline. The | symbol hands objects from one command to the next. You’ll use four commands with it all the time: Where-Object to filter rows, Sort-Object to order them, Select-Object to choose columns or the first few, and Measure-Object to count, sum or average.
Format last. Format-Table and Format-List turn objects into text for the screen, so keep them for the very end, because whatever comes after them gets display instructions and not data.
Execution policy. Windows Server defaults to RemoteSigned, which lets scripts you write locally run but makes scripts downloaded from the internet be signed or unblocked first. Think of it as a seat belt against running something you downloaded by accident, and don’t mistake it for a security boundary.
Safety switches. A lot of commands that change things support -WhatIf (show what would happen and change nothing) and -Confirm. Whenever a pipeline might touch more objects than you expect, add -WhatIf.
How it works, step by step
This is a pipeline you’ll build in the lab, a stage at a time. Each stage takes objects in, does one job and passes objects on:
- Get-Service produces one object per service on the server, which is about 250 on a fresh Server 2025.
- Where-Object keeps the ones you want, for example services set to start automatically that aren’t running.
- Sort-Object puts them in order, by name or by any property.
- Select-Object keeps the columns you care about and drops the rest.
- Export-Csv writes them to a file you can open in Excel or attach to a ticket.
No stage in this chain cuts up text. They all work with real properties, and that’s why the same pipeline works on any server in any language.
And this is why that matters, compared with the old way of doing things:
You’ll still come across text tools like ipconfig and netstat, and they work fine inside PowerShell. When you need to filter, compare or report, though, use the PowerShell version (Get-NetIPConfiguration, Get-NetTCPConnection) so you get objects back.
Hands-on Lab: PowerShell for Windows Server, from commands to a script
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Start DC01, sign in and open Windows PowerShell as administrator. Your lists will be a little different from the examples, but they’ll have the same shape.
1Find commands by guessing their names
Run this:
Get-Command -Verb Get -Noun *Service*You should see something like this (the list may be longer):
CommandType Name Version Source
----------- ---- ------- ------
Function Get-NetFirewallServiceFilter 2.0.0.0 NetSecurity
Cmdlet Get-Service 3.1.0.0 Microsoft.PowerShell.ManagementYou guessed the verb (Get) and part of the noun (Service), and PowerShell found the matching commands. Try Get-Command -Noun *DnsClient* or Get-Command *TimeZone* in the same way.
✅ Checkpoint: Get-Service appears in your list.
2Get help with real examples
Run these (the first one downloads help and takes a minute):
Update-Help -ErrorAction SilentlyContinue
Get-Help Get-Service -ExamplesEach numbered example has an explanation under it. Help works for every cmdlet, and Get-Help about_Pipelines explains concepts too. -ErrorAction SilentlyContinue hides the warnings from the few modules whose help can’t be downloaded.
✅ Checkpoint: Get-Help shows several examples for Get-Service.
3Look inside an object
Run this:
Get-Service -Name Spooler | Get-Member -MemberType PropertyYou should see something like this:
TypeName: System.ServiceProcess.ServiceController
Name MemberType Definition
---- ---------- ----------
CanPauseAndContinue Property bool CanPauseAndContinue {get;}
CanShutdown Property bool CanShutdown {get;}
CanStop Property bool CanStop {get;}
Container Property System.ComponentModel.IContainer Container {get;}
DependentServices Property System.ServiceProcess.ServiceController[] DependentServices {get;}
DisplayName Property string DisplayName {get;set;}
MachineName Property string MachineName {get;set;}
ServiceHandle Property System.Runtime.InteropServices.SafeHandle ServiceHandle {get;}
ServiceName Property string ServiceName {get;set;}
ServicesDependedOn Property System.ServiceProcess.ServiceController[] ServicesDependedOn {get;}
ServiceType Property System.ServiceProcess.ServiceType ServiceType {get;}
Site Property System.ComponentModel.ISite Site {get;set;}
StartType Property System.ServiceProcess.ServiceStartMode StartType {get;}
Status Property System.ServiceProcess.ServiceControllerStatus Status {get;}On its own, Get-Service shows only Status, Name and DisplayName, but the object holds a lot more, including StartType and DependentServices (the services that stop when this one stops). Any time you wonder “what can I filter on?”, pipe it to Get-Member.
✅ Checkpoint: You can see StartType and Status in the property list.
4Filter, sort and select
Find services that are set to start automatically but aren’t running:
Get-Service |
Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' } |
Sort-Object Name |
Select-Object Name, Status, StartTypeYou should see something like this:
Name Status StartType
---- ------ ---------
edgeupdate Stopped Automatic
sppsvc Stopped Automatic$_ means “the object passing through right now”. This is a real admin check, because automatic services that aren’t running are the first place to look when a server “isn’t working”. Some of them, like the update services above, start automatically and then stop by design, so read the list instead of restarting everything on it.
✅ Checkpoint: You got a short list of automatic services that are stopped.
5Count and measure
Run these one at a time:
(Get-Service | Where-Object Status -eq 'Running').Count
Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 3 Name, @{n='MemMB';e={[math]::Round($_.WorkingSet/1MB)}}You should see something like this:
112
Name MemMB
---- -----
MsMpEng 212
ServerManager 189
svchost 104The first line counts running services, and the second shows the three processes using the most memory with a calculated MB column. Both patterns come back in Lesson 47, when you deal with a slow server.
✅ Checkpoint: You can see the number of running services and the top three memory users.
6Export to CSV and read it back
Run this:
New-Item -ItemType Directory -Path C:\Lab -Force | Out-Null
Get-Service | Select-Object Name, Status, StartType | Export-Csv C:\Lab\services.csv -NoTypeInformation
Import-Csv C:\Lab\services.csv | Select-Object -First 3You should see something like this:
Name Status StartType
---- ------ ---------
AppIDSvc Stopped Manual
Appinfo Running Manual
AppMgmt Stopped ManualThe CSV opens in Excel, and Import-Csv turns it back into objects. That’s how you hand a list to a manager, or compare a server today against the same list from last month.
✅ Checkpoint: C:\Lab\services.csv exists and Import-Csv shows the first three services.
7Write and run a small script
Create the script:
notepad C:\Lab\check.ps1Paste this into Notepad, then save and close it:
# check.ps1: a quick health summary for this server
$os = Get-CimInstance Win32_OperatingSystem
$stopped = Get-Service | Where-Object { $_.StartType -eq 'Automatic' -and $_.Status -ne 'Running' }
"Server: $env:COMPUTERNAME"
"Uptime (hours): {0:N1}" -f ((Get-Date) - $os.LastBootUpTime).TotalHours
"Free C: (GB): {0:N1}" -f ((Get-Volume -DriveLetter C).SizeRemaining / 1GB)
"Auto but stopped: $($stopped.Count)"Run it:
C:\Lab\check.ps1You should see something like this:
Server: DC01
Uptime (hours): 1.4
Free C: (GB): 44.8
Auto but stopped: 2
Those four lines sum up a server in a file you can run anywhere. -f is the format operator, and {0:N1} means “first value, one decimal place”. In Lesson 27 you’ll run scripts like this on many servers at the same time.
✅ Checkpoint: Your script prints the server name, uptime, free space and the count of stopped automatic services.
Break It, Then Fix It
These are two classic PowerShell mistakes that every admin makes once, formatting before exporting and running a downloaded script.
1Break it: export after Format-Table
Run this on DC01:
Get-Service | Format-Table Name, Status | Export-Csv C:\Lab\broken.csv -NoTypeInformation
Import-Csv C:\Lab\broken.csv | Select-Object -First 2 | Format-ListYou’ll get something like this instead of service names:
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 033ecb2bc07a4d43b5ef94ed5a35d280
pageHeaderEntry :
pageFooterEntry :
autosizeInfo :
shapeInfo : Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo
groupingEntry :
ClassId2e4f51ef21dd47e99d3c952918aff9cd : 9e210fe47d09416682b841769c78b8a3
pageHeaderEntry :
pageFooterEntry :
autosizeInfo :
shapeInfo :
groupingEntry :There’s no error, only rubbish. Format-Table turned the services into drawing instructions for the screen and Export-Csv saved those instructions faithfully. The odd ClassId2e4f51ef21dd47e99d3c952918aff9cd column gives it away.
To fix it, choose the columns with Select-Object and keep Format-* for the screen only:
Get-Service | Select-Object Name, Status | Export-Csv C:\Lab\fixed.csv -NoTypeInformation
Import-Csv C:\Lab\fixed.csv | Select-Object -First 2You should see something like this:
Name Status
---- ------
AppIDSvc Stopped
Appinfo Running✅ Checkpoint: broken.csv is full of ClassId lines; fixed.csv has real service names. Rule: Format last, or not at all.
2Break it: run a “downloaded” script
Copy your script and mark the copy as downloaded from the internet, the way a browser would:
Copy-Item C:\Lab\check.ps1 C:\Lab\downloaded.ps1
Set-Content -Path C:\Lab\downloaded.ps1 -Stream Zone.Identifier -Value "[ZoneTransfer]",'ZoneId=3'
C:\Lab\downloaded.ps1You’ll get an error like this:
C:\Lab\downloaded.ps1 : File C:\Lab\downloaded.ps1 cannot be loaded. The file C:\Lab\downloaded.ps1 is not digitally
signed. You cannot run this script on the current system. For more information about running scripts and setting
execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ C:\Lab\downloaded.ps1
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
Browsers attach a hidden “Zone.Identifier” note to every file they download, and ZoneId 3 means “from the internet”. Under the RemoteSigned policy, PowerShell refuses unsigned scripts carrying that note, while the same file without the note runs fine, which is why your own check.ps1 worked.
To fix it, read the script first, and unblock it only if you trust it:
Get-Content C:\Lab\downloaded.ps1
Unblock-File C:\Lab\downloaded.ps1
C:\Lab\downloaded.ps1Please don’t “fix” this by setting the execution policy to Unrestricted or Bypass for the whole server. Unblock-File on a script you’ve read is the right way to do it.
✅ Checkpoint: The script was refused while marked as downloaded and ran after Unblock-File.
This happened at work
The cleanup script that disabled everyone
An admin was asked to disable user accounts that hadn’t signed in for 90 days. He wrote a one-line pipeline to get all users, keep those whose LastLogonDate was older than 90 days and disable them. He tried the filter on screen, a few names looked right, so he added the disable command to the end and ran it.
Within minutes the helpdesk was flooded, because about 1,800 accounts had been disabled, his own manager’s among them. Get-ADUser returns only a handful of properties unless you ask for more, and LastLogonDate isn’t one of them, so it was empty for every user. PowerShell treats “empty is less than a date” as true, and every account matched.
It took an hour to enable them all again, using the same pipeline with Enable-ADAccount and the event log as the list.
The fix: any script that changes many objects now has to request the properties it filters on (-Properties LastLogonDate), show a count before it acts, run once with -WhatIf and get a second person to review it. Anything that touches more than 50 accounts needs a change ticket.
The lesson: PowerShell does what you wrote at computer speed, so check how many objects a pipeline will touch before you let it change them.
Common mistakes and troubleshooting
| Mistake or symptom | What happens | What to do instead |
|---|---|---|
| Format-Table before Export-Csv or other commands | Output full of ClassId2e4f51ef21dd47e99d3c952918aff9cd | Use Select-Object for columns; Format only at the end, for the screen |
| “cannot be loaded because running scripts is disabled” | Scripts won’t run (common on Windows client, policy Restricted) | Set-ExecutionPolicy RemoteSigned -Scope CurrentUser on your own machine |
| “is not digitally signed” for a downloaded script | The script is blocked | Read it, then Unblock-File |
| Filtering on a property that isn’t there | Every object matches (or none do) | Check with Get-Member and request properties with -Properties |
| Running a change pipeline without checking | Touches far more objects than expected | Count first, then -WhatIf, then run |
| Parsing text from ipconfig or netstat | Breaks with another language or format | Use Get-NetIPConfiguration, Get-NetTCPConnection and other cmdlets |
| “The term … is not recognized” | Typo, or the module isn’t installed | Get-Command *partofname*; install the RSAT or role module |
| Short help with no examples | Help files weren’t downloaded | Update-Help as administrator |
| Using aliases in scripts (gsv, ?, %) | Scripts are hard to read and review | Use full names in scripts; aliases only at the prompt |
Interview questions
Click a question to open it. Each one is written the way an interviewer would ask it. Under it you will see why they ask it and one way you could answer, in your own words.
Fresher level
1. Can you explain what a cmdlet is, and how PowerShell commands are usually named?
Why they ask this: If you understand the naming pattern you can find commands you’ve never used, and that’s the basic they’re checking.
How you might answer: A cmdlet is a PowerShell command, named Verb-Noun with an approved verb, like Get-Service or Restart-Computer.
Because of that they’re easy to guess and easy to find with Get-Command.
2. You run a command and get an object back, but you don’t know what properties it has. How would you find out?
Why they ask this: They want someone who explores PowerShell rather than memorising it, because that’s how you solve new problems on your own.
How you might answer: I’d pipe it to Get-Member, for example Get-Service | Get-Member, and that lists the properties and methods.
If I want every property value for one object, I’d use Select-Object *.
3. How would you explain to a new team member what the pipeline does in PowerShell?
Why they ask this: Passing objects instead of text is what sets PowerShell apart from older shells, and they want to hear that you get it.
How you might answer: I’d tell them the pipeline passes objects from one command to the next, so each command works with real properties and doesn’t have to cut up text.
2–5 years experience
4. A teammate’s script puts Format-Table before Export-Csv, and the CSV comes out full of strange data. What went wrong?
Why they ask this: It’s a common problem, and knowing the fix shows you’ve done real hands-on work with PowerShell.
How you might answer: Format cmdlets turn objects into display instructions, so anything after them, like Export-Csv, gets those instructions and not the real data.
I’d pick the properties with Select-Object and only use Format-Table as the very last command, for display.
5. What does the RemoteSigned execution policy actually protect you from, and what doesn’t it protect you from?
Why they ask this: Lots of people think it’s a security wall when it isn’t, so they want to see you know what it does and doesn’t do.
How you might answer: With RemoteSigned, local scripts run, but anything marked as downloaded has to be signed by a trusted publisher, so it stops you running a downloaded script by accident.
It isn’t a security boundary though, since anyone can paste the code straight into the console.
6. You need to disable 300 user accounts with one PowerShell command. How would you make that change safely?
Why they ask this: One wrong filter can hit thousands of objects, so they want to hear a safe habit for bulk changes.
How you might answer: I’d request the properties I need and show the count and a sample first. Then I’d run it with -WhatIf, and after that for real, ideally on a small group to begin with.
I’d log what changed as well, so we can reverse it.
Senior level
7. Everyone on your admin team writes PowerShell scripts their own way. How would you bring some standards to it?
Why they ask this: Scripts outlive the people who wrote them, so they want to see you think about maintaining them.
How you might answer: I’d move scripts into version control with peer review and agree on a style: full cmdlet names, comment-based help, and parameters rather than hard-coded values.
Each script should have error handling, logging and -WhatIf support, and anything that runs with high privilege should be signed too.
8. When would you sign your PowerShell scripts, and how would you do it?
Why they ask this: Code signing matters most for automation that runs with high rights, and they want to know you’ve done it in practice.
How you might answer: When policy requires AllSigned, or for scripts that privileged automation runs. I’d get a code-signing certificate from our internal CA and sign with Set-AuthenticodeSignature.
I’d also guard the signing key carefully, because whoever has it can sign scripts in our name.
9. On your servers, would you use Windows PowerShell 5.1 or PowerShell 7? Why?
Why they ask this: Picking the right version avoids module problems, so they want to see you know both exist and why.
How you might answer: Windows PowerShell 5.1 comes with Windows and runs every Windows module. PowerShell 7 is cross-platform and faster and gets the new features, but you install it separately.
I’d use 7 day to day and drop back to 5.1 when a module needs it.
Quick quiz
Q1. Which command lists the properties of an object?
- Get-Help
- Get-Member
- Get-Command
Show answer
B — Get-Member shows properties and methods.
Q2. What does $_ mean inside Where-Object { }?
- The previous command
- The current object in the pipeline
- A variable for errors
Show answer
B — $_ is the object currently passing through.
Q3. Why did broken.csv contain ClassId columns?
- Export-Csv is broken
- Format-Table came before Export-Csv
- The services were stopped
Show answer
B — Format cmdlets output display instructions, not data.
Q4. What blocked downloaded.ps1?
- A missing file
- The Zone.Identifier mark plus the RemoteSigned policy
- A syntax error
Show answer
B — RemoteSigned blocks unsigned scripts marked as downloaded.
Q5. In the work story, why were all accounts disabled?
- A virus
- LastLogonDate wasn’t requested, so it was empty for everyone and the filter matched all
- The domain controller failed
Show answer
B — Always request the properties you filter on and check the count first.
Quick recap
- PowerShell for Windows Server uses Verb-Noun cmdlets, which you find with
Get-Command, and you get examples withGet-Help -Examples. - Commands pass objects, and
Get-Membershows you what’s inside them. - The core pipeline:
Where-Object,Sort-Object,Select-Object,Measure-Object,Export-Csv. - Format last, and use Format-Table only for the screen.
- RemoteSigned blocks downloaded scripts, so read them first and then
Unblock-File. - Before a bulk change: request properties, count, -WhatIf, then run.
Next lesson
Lesson 8: Windows internals for admins → You’ll look under the hood: processes, services and their accounts, the registry, how Windows boots, and where the logs live, so the troubleshooting lessons make sense.
Further reading: PowerShell for Windows Server
To go further with PowerShell for Windows Server, start with Microsoft’s PowerShell documentation, in particular the pages on the pipeline and execution policies. The full plan for this course is on the Windows Server Administration course page.
