PowerShell History – How to View Full History, Not Just Current Session

historypowershell

Powershell now handily remembers history from previous sessions, and I can get to earlier commands simply by using the up-arrow. What I would like though is to be able to display this history, but I can't figure out how to do it.

The command get-history for some reason only seems to be able to display the history for the current session. Even passing the -count option doesn't help.

At the moment the only way I can get to a previous command is to manually up-click through all previous commands to find the one I'm looking for. This obviously can be quite tedious if the command was run a while ago.

Is there some trick to make get-history work correctly, across sessions. This list is obviously stored somewhere, so it aught to be possible to display it.

edit: This isn't a duplicate question. This is about accessing the full history which is already recorded by Powershell, not about adding a new (custom) way to save session history. Those other questions and associated answers were relevant before Powershell had the ability to automatically record full command history.

Best Answer

I have this in my PS profile:

function hist { 
  $find = $args; 
  Write-Host "Finding in full history using {`$_ -like `"*$find*`"}"; 
  Get-Content (Get-PSReadlineOption).HistorySavePath | ? {$_ -like "*$find*"} | Get-Unique | more 
}
Related Question