Commands / Help and discovery

Get-History

See commands you ran earlier

beginner Help and discovery Aliases hhistoryghy

Get-History
 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

ShellWhat you might type
bash / zshhistory 20
cmd.exedoskey /history

More in From bash and From cmd.

Related commands