Skip to content

Limit size of ConsoleHost_history.txt file #537

@jdthorpe

Description

@jdthorpe

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRA PR is opened targeting the issueIssue-EnhancementIt's a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions