August 7th, 2018

PowerShell PowerTip: History of commands with PSReadline

Kory Thacher
Premier Field Engineer

One of the really cool things PSReadline provides (module shipping on v5+) isn’t as immediately obvious as the syntax highlighting. It offers a persistent history that is stored from session to session.

This means if you run commands in a window, close it, and open a new one later you can still hit the up arrow and scroll through them. I use this feature quite a bit doing demos or just working on things where I want to clear out my whole scope and jump back in.

If you want to opt out you can as well:

<span>Set-PSReadLineOption -</span><span class="highlight" id="0.6822782376879328" name="searchHitInReadingPane">History</span><span>SaveStyle </span><span>SaveAtExit #will only save the history once you close the window</span>

<span>Set-PSReadLineOption -</span><span class="highlight" id="0.6822782376879328" name="searchHitInReadingPane">History</span><span>SaveStyle SaveNothing #turns this off</span>

Hope that helps, tune in more often to get short and sweet PowerTips!

Author

Kory Thacher
Premier Field Engineer

I've been a PFE since 2012, working with various technologies. I live in the modern applications domain, doing work in UWP apps, .NET, Unity, DevOps, and of course PowerShell. I've been teaching PowerShell related workshops very frequently for years, and I really enjoy getting the opportunity to explain a topic or learn something new from my colleagues. I enjoy scripting because of how fast and interactive it can be, and I love getting interesting problems to work on with customers. ...

More about author

0 comments

Discussion are closed.