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.

  • This isn't exactly a duplicate. Powershell by default now remembers the history, which is previously couldn't do. I'm just wanting to access this already existing history. The answers for that other question are kind of hacks. There should be some other way now to do it natively. – user1751825 Apr 5 '17 at 23:12
  • If you use the console host and the PSReadline module, the history is written to a text file and preserved between sessions. (PSReadline is baked in on Windows 10.) – Bill_Stewart Apr 6 '17 at 21:28
  • New versions of Powershell automatically save history to %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt – Dan Stevens Jun 8 '18 at 10:18
  • Nope, different question. – charles ross Feb 17 at 1:08
  • Get-Content (Get-PSReadlineOption).HistorySavePath | more – charles ross Feb 17 at 1:08

The solution commented by "charles ross" is what I was looking for:

Get-Content (Get-PSReadlineOption).HistorySavePath | more

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.