6

Is there a way to have PowerShell remember commands entered during the previous sessions? That is, after closing the window and opening it again, can PowerShell be setup to remember the commands?

Louis Waweru
  • 25,409
  • 45
  • 137
  • 203

2 Answers2

3

This answer applies only to older PowerShell versions. At least since ver. 5 PowerShell persists history to a file automatically

With a little bit of scripting you could set this up, even without third party software. I would recommend reading the help on Get-History, Add-History, and about_History.

As the help explains, you can use Get-History to get your current history and with a command such as Get-History | Export-CliXml C:\History.CliXml save it to a file. Following that, you could import your history using the Add-History command.

(The Add-History help file actually explains how to do this in more detail.)

I would expect that it is possible to configure your environment to perform these actions automatically, although I would question the usefulness of such a setup.

ndemou
  • 1,280
  • 1
  • 13
  • 21
Mark
  • 194
  • 2
3

The Windows PowerShell in Windows 10 has this functionality by default.

The history file is located at AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt.

Louis Waweru
  • 25,409
  • 45
  • 137
  • 203