Your First Commands
Prerequisites: Installing PowerShell 7
PowerShell commands — cmdlets — are named Verb-Noun:
Write-Output "Hello, world!"
Get-Date -Year 2025 -Month 4 -Day 22 -Format "dddd, d MMMM yyyy"
Expected output
Hello, world!
Tuesday, 22 April 2025
Write-Outputsends a value down the pipeline — at the end of the pipeline, PowerShell displays it.Get-Dategets a date; its parameters (-Year,-Format) start with a dash and are followed by a value.
Try a few more on your own machine:
# illustrative
Get-Location
Get-ChildItem
Get-Process | Select-Object -First 3
Verbs are standardized
A small set of approved verbs covers almost everything:
| Verb | Does | Example |
|---|---|---|
Get |
retrieves something | Get-Service |
Set |
changes something | Set-Location |
New |
creates something | New-Item |
Remove |
deletes something | Remove-Item |
Start / Stop |
starts or stops | Stop-Process |
Test |
checks, returns true/false | Test-Path |
Get-Verb lists them all.
Case and shortcuts
- PowerShell is not case-sensitive:
get-date,Get-Date, andGET-DATEall work. The convention in scripts isVerb-Nouncapitalization. - Aliases are short names for common commands:
ls,dir, andgciall runGet-ChildItem;cdrunsSet-Location. They're handy when typing, but write full names in scripts, for readability. - Parameter names can be shortened while they're unambiguous:
-Fofor-Format.
Common mistakes
- A space in the wrong place:
Get -Dateruns a command calledGet. - Forgetting quotes around values with spaces:
Write-Output Hello worldpasses two separate values.
Practice
Print your name on one line and your favorite food on the next with two
Write-Output commands.
Show solution
Write-Output "Ada"
Write-Output "Pizza"
Ada
Pizza