Your First Commands
Scope: the Verb-Noun pattern, getting help, and running your first script. All examples were run with PowerShell 7.5.
Verb-Noun: the naming system
Every PowerShell command is Verb-Noun:
Get-Process
Get-Service
Get-ChildItem
Set-Location
Approved verbs (Get, Set, New, Remove, Start, Stop,
Test...) keep the whole ecosystem guessable. Don't know the
command? Guess the verb and noun — you're often right.
The three discovery commands
Get-Command *service* # find commands with "service" in the name
Get-Help Get-Process # read the manual
Get-Help Get-Process -Examples # skip to the examples (the useful part)
Get-Command finds things, Get-Help explains them,
Get-Member (coming up) inspects objects. These three answer
most "how do I...?" questions without leaving the terminal.
Tab completion works everywhere — type Get-Pro and hit Tab.
Your first pipeline
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
Read it left to right: get all processes, sort by CPU usage,
take the top 5. No text parsing — CPU is a real property.
(See Objects and the Pipeline for the
full story.)
Running a script
Create hello.ps1:
Write-Host "Hello, world!"
.\hello.ps1
Note the .\ — like Bash, PowerShell doesn't run scripts from
the current directory without an explicit path (a security
habit).
On Windows, if it refuses to run, that's the execution policy — see Installing PowerShell.
Write-Output vs Write-Host
Write-Output "hello" # sends to the pipeline (the default)
Write-Host "hello" # writes to the screen only
This distinction matters: Write-Host output can't be captured
or piped — it's for humans only. In functions that return data,
use Write-Output (or just leave the value on a line by
itself). Write-Host is for progress messages.
Comment-based help
<#
.SYNOPSIS
Says hello.
.DESCRIPTION
A longer explanation of what the script does.
.EXAMPLE
.\hello.ps1
#>
Write-Host "Hello, world!"
Get-Help .\hello.ps1 reads this block. Writing it for shared
scripts is good manners.
Check
- [ ] You can find a command with
Get-Commandand read its examples withGet-Help -Examples - [ ] You can run a
.ps1script with.\ - [ ] You can say when to use
Write-HostvsWrite-Output
Next: Variables and Types.