Get-History
See commands you ran earlier
Get-History -Count 20
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Get-History
Shows what you typed in the current window. Each entry has an Id. Invoke-History 12 (alias r 12) runs entry 12 again.
Get-History forgets everything when you close the window. PSReadLine keeps a longer history in a file across sessions. Press Ctrl+R at the prompt to search it.
Try this
Save this session's commands to a script to tidy up later:
Get-History | Select-Object -ExpandProperty CommandLine | Set-Content -Path .\what-i-did.ps1
Where the long-term history file lives:
(Get-PSReadLineOption).HistorySavePath
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | history 20 |
| cmd.exe | doskey /history |
More in From bash and From cmd.