Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

View full history for powershell, not just current session

Writer Andrew Mclaughlin

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.

5

2 Answers

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
}
2

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

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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