Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save and load history in powershell PSReadLine module?

I'm using great PSReadLine module for Powershell and I really like that is persist my history of commands. But I need to reinstall my system. What is the easiest way to save this history (probably to file) an load it after fresh install of PSReadLine?

like image 745
Mariusz Pawelski Avatar asked Feb 01 '16 09:02

Mariusz Pawelski


People also ask

What is the difference between PowerShell get-history and PSReadLine?

2 Get-History accesses the PowerShellhistory (current session only). PSReadLine uses its own history (in memory and saved in (Get-PSReadLineOption).HistorySavePath).

How can I optimize the PSReadLine history file?

Here is a function I wrote to optimize the PSReadline history file. You can get the code from Github. The PSReadline module can maintain a persistent command-line history. However, there are no provisions for managing the file. When the file gets very large, performance starting PowerShell can be affected.

How do I manage the history file in PowerShell?

However, there are no provisions for managing the file. When the file gets very large, performance starting PowerShell can be affected. This command will trim the history file to a specified length as well as removing any duplicate entries. Set the maximum number of lines to store in the history file.

What is PS read line in PowerShell?

PSReadLine is a module created by Microsoft to customize the command line editing environment in PowerShell. It offers numerous customizations that can change how your command line editor presents data in many ways. Mike Kanakos is a Cloud and Datacenter Microsoft MVP, tech blogger and PowerShell community leader.


1 Answers

PSReadline module save command history in file. All you need is to backup that file and restore it after reinstalling your system. You can get file name of history file by following command:

(Get-PSReadlineOption).HistorySavePath
like image 60
user4003407 Avatar answered Oct 02 '22 13:10

user4003407