The single most important PowerShell command that you will ever learn

Agoney Garcia-Deniz
2 min readJun 27, 2020

Have you ever found yourself hitting the up arrow key endlessly until you find that command that you know you typed but don’t quite remember? or maybe you’ve closed the session so Get-History won’t help and just have to hit the up arrow key until you see the command and invariably the down when you’ve gone too far.

I wondered how the command history was stored and it turns out that it’s stored in a plain text file in this location:

C:\Users\__username__\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

It’s not exactly a memorable location and here is where The most important PowerShell command that you will ever learn comes in so without further ado, here it is:

(Get-PSReadlineOption).HistorySavePath

I’ve modified my PowerShell profile to delete the history alias and list the contents of this file instead:

del alias:history -force 2> $null
function history {Get-Content (Get-PSReadlineOption).HistorySavePath}

So that Get-History gets the session history and history gets the whole history

I should also note that this also works in PowerShell Core

--

--