在Powershell_ISE版本10.0.19041.1 (Windows10)宿主中运行Powershell 5.1.19041.1682时,将HistorySavePath属性设置为完整的文件路径,但是在ISE窗口中运行命令后从未创建该文件。我在ISE脚本窗格、输出窗格中执行命令,保存了一个ps1文件,关闭了ISE并重新打开。从未创建HistorySavePath文件。
在控制台主机中运行Powershell时,将创建由HistorySavePath属性(Consol eHost_history.txt)表示的文件,并将历史记录写入该文件。另外,(Get-PSReadLineOption).AddToHistoryHandler是为控制台主机填充的,而对于ISE则是空的。
为什么"Windows Host_history.txt“历史文件丢失,AddToHistoryHandler主机空白?
- ISE主机PSReadLine选项
>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 -控制台主机PSReadLine选项
   >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发布于 2022-11-29 16:39:51
ISE多年来一直不受欢迎,您最好不要再使用它了,因为环境和几个cmdlet的行为不同,VSCode在linting、代码高亮化和使用现代PowerShell版本的7+方面要好得多。
https://stackoverflow.com/questions/74188327
复制相似问题