Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Managing the PSReadline History File

Posted on November 2, 2017

It has taken some discipline but I have finally gotten the hang of using the command history file maintained by PSReadline. Even though Set-PSReadlineOption has a few options on how to use this file, in my experience I have felt the need to handle a few things on my own. Here's my take.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I have found that my history file can get quite large which seems to be affecting performance loading PowerShell, or it could just be a coincidence. Even though there are settings to control the maximum number of lines and to keep out duplicate commands, PSReadline doesn't seem to do anything with these values. Perhaps in earlier versions of Windows it did but I am running 5.1.16299 and nothing seems to keep the history file in check. It is just as easy to handle this myself.

Here is a function I wrote to optimize the PSReadline history file. You can get the code from Github.

The function will trim your history file to a specified number of lines. The default is the global $MaximumHistoryCount variable. The function will also delete duplicate entries, further reducing the file size.  In my PowerShell profile script I dot source the function and run it. Now at least I can keep the file somewhat in check.

If you encounter problems or have feedback, please post an issue on the gist page.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

1 thought on “Managing the PSReadline History File”

  1. Tommy Becker says:
    November 5, 2017 at 5:49 am

    Good ideas.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d