Things I Learned #23: History of commands in PowerShell

1 minute read til technology   til   powershell   learning   windows Comments

Here’s a quick-and-dirty thing I learned today. I was trying to figure out what exactly I did two years ago when I moved my blog to Jekyll; I wanted to know exactly which programs I ran, what I did in Docker, etc. Since all of that work was done on my Windows machine, I had no idea if it was even possible to have command history going back that far.

On my Mac, I can just pop open my .zsh_history file and find what I need. I have zsh configured to keep a huge buffer of commands because you never know when something like this may come up. I never specifically configured anything on Windows, BUT I found out that Powershell DOES have a similar file. It doesn’t have the timestamp like my .zsh_history does, but it’s better than nothing.

What I Learned

The file is buried deep within the AppData folder, but finding the path is easy with a simple Powershell command:

PS> (Get-PSReadlineOption).HistorySavePath

As always, Powershell fails on intuitive commands, so I did have to search for this one because there’s no way I’d just stumble on it.

On my machine, that dumps out a path like this:

E:\AppData\Roaming\Microsoft\Windows\Powershell\PSReadline\ConsoleHost_history.txt

My file contains 17,740 lines, each representing something I did in Powershell. In fact, the last couple entries are the

(Get-PSReadlineOption).HistorySavePath
vim E:\AppData\Roaming\Microsoft\Windows\Powershell\PSReadline\ConsoleHost_history.txt

Cool.

I was able to go back to when I ran

jekyll new ssdd

and trace the exact things I did to move from WordPress to Jekyll (coming in another post). Going through this file also reminded me that I took a different approach on another one of my old blogs, so maybe I’ll talk about that, too.

I hope you enjoyed this tip!


A seal indicating this page was written by a human

Updated:

Comments