powershellpsreadline

Why is PSReadLine History File missing and PSReadLineOption AddToHistoryHandler is blank in Powershell 5 ISE?


When running Powershell 5.1.19041.1682 in the Powershell_ISE Version 10.0.19041.1 (Windows 10) host the HistorySavePath property is set to a full file path however the file is never created after running commands in the ISE window. I have executed commands in the ISE Script pane, the output pane, saved a ps1 file, closed the ISE Host and re-opened. The HistorySavePath file is never created.

When running Powershell in a Console host the file denoted by the HistorySavePath property (Consol eHost_history.txt) is created and history is written to the file. Also, (Get-PSReadLineOption).AddToHistoryHandler is populated for the Console Host but is blank for the ISE Host.

Why is the "Windows PowerShell ISE Host_history.txt" history file missing and AddToHistoryHandler blank for ISE Host ?

- ISE Host PSReadLine Option

>Get-PSReadLineOption

EditMode                               : Windows
AddToHistoryHandler                    : 
HistoryNoDuplicates                    : True
HistorySavePath                        : C:\Users\Admin\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\Windows PowerShell ISE Host_history.txt
HistorySaveStyle                       : SaveIncrementally
HistorySearchCaseSensitive             : False
HistorySearchCursorMovesToEnd          : False
MaximumHistoryCount                    : 4096 

- Console Host PSReadLine Option

   >Get-PSReadLineOption

EditMode                               : Windows
AddToHistoryHandler                    : System.Func`2[System.String,System.Object]
HistoryNoDuplicates                    : True
HistorySavePath                        : C:\Users\Admin\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\Consol
                                         eHost_history.txt
HistorySaveStyle                       : SaveIncrementally
HistorySearchCaseSensitive             : False
HistorySearchCursorMovesToEnd          : False
MaximumHistoryCount                    : 4096

Solution

  • ISE is deprecated since many years, you better not use it anymore because of the environment and several cmdlets behave differently and VSCode is far superior for linting, code highlighting and working with modern PowerShell versions 7+.