Get-Content
Read a text file
Get-Content -Path .\notes.txt
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Get-Content
- PowerShell 7 On Linux and macOS, cat runs the system command instead of this cmdlet. Type the full cmdlet name there.
What you'll see
Buy milk
Call the printer company
Back up the laptop on Friday
Reads a file as an array of lines. -TotalCount 20 is the first 20 lines. -Tail 20 is the last 20.
Do not use this on huge binaries. For CSV, prefer Import-Csv.
Try this
Get-Content -Path .\notes.txt -Tail 10
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | cat notes.txt |
| cmd.exe | type notes.txt |
More in From bash and From cmd.