question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Limit size of ConsoleHost_history.txt file

See original GitHub issue

Recently, accessing command history via the up-arrow has been quite slow (3-5 seconds to respond), and today, when I opened PowerShell, the console was non-responsive and after about 3 mintues would throw the error below:

Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\Users\me\Documents>
Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 0 Keys:


Exception:
System.OutOfMemoryException: Array dimensions exceeded supported range.
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)
   at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
   at System.Collections.Generic.List`1.Add(T item)
   at System.IO.File.InternalReadAllLines(String path, Encoding encoding)
   at Microsoft.PowerShell.PSConsoleReadLine.<ReadHistoryFile>b__67_0()
   at Microsoft.PowerShell.PSConsoleReadLine.WithHistoryFileMutexDo(Int32 timeout, Action action)
   at Microsoft.PowerShell.PSConsoleReadLine.DelayedOneTimeInitialize()
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------

With little digging I found that the console history file found here:

C:\Users\me\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

had grown to 13MB and contained about 3 months of commands, and deleting the file fixed both issues.

How can the size of this file be moderated?

Environment data

PS version: 5.1.14393.1198 PSReadline version: 1.2 os: 10.0.14393.0 (rs1_release.160715-1616) PS file version: 10.0.14393.0 (rs1_release.160715-1616)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:22 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
lzybkrcommented, Apr 16, 2018

Sorry about that @dennisroche. You’re the third to report this issue, fortunately it is fixed in 2.0.0-beta1.

1reaction
rably1960commented, Nov 15, 2022

I know this is an old incident, but have there been any thoughts on implementing a way to limit the size of the history file? “MaximumHistoryCount” is only how many lines are read from the file and put into your history. It has nothing to do with the file size, so the file will continue to get bigger forever. A multi-GB history file serves no purpose and is just a waste of space.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing the PSReadline History File
Trim the PSReadlineHistory file to default maximum number of lines. Trim the PSReadlineHistory file to 500 lines and display the file listing.
Read more >
How to Use PowerShell History Feature
The maximum default history entries are 4096 as stored in the MaximumHistoryCount ... PowerShell can export nearly anything to a text file; ...
Read more >
Set-PSReadLineOption (PSReadLine) - PowerShell
Computers running Windows or non-Windows platforms store the file in different locations. The filename is stored in a variable $($Host.Name)_history.txt , for ...
Read more >
PowerShell History File | 0xdf hacks stuff - GitLab
I came across a situation where I discovered a user's PSReadline ConsoleHost_history.txt file, and it ended up giving me the information I ...
Read more >
Console history single command length limit - powershell
I've come to notice, that long multi line commands are not logged to the ConsoleHost_history.txt in PowerShell 7 (unlike in PowerShell 5). How ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found