Posted on December 22, 2015 · Posted in Powershell

PowerShell Commands History

One of the main drawbacks of Powershell command prompt compared to bash was the inability to keep a history of executed commands. The command history could be viewed only in the current Powershell session, and when Powershell console has been closed or the computer has been restarted, the command history is not saved. This drawback has been fixed in PowerShell v5, which is integrated into Windows 10.

Now when you press the up arrow key you can go to the last command you entered or to the previous ones (down arrow). By default, PowerShell remembers 4096 commands stored in a plain text file in the profile of each user %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt. The history is stored separately for PowerShell and ISE.

\ConsoleHost_history.txt - powershell commands history

You can search the command history using CTRL+R (reverse search) or CTRL+S (forward search). The text you entered will be found in the command history in any position (unlike search in PowerShell using F8 or Shift+F8, which allow to look for the matches from the beginning of the line only) and a suitable variant will be highlighted.

Powershell history search

Note. The feature of command history in PowerShell 5 is based on a third-party module PSReadLine, which considerably extends the functions of PowerShell console. In Windows 10, it is located in C:\Program Files\WindowsPowerShell\Modules\PSReadline and automatically imported when you start PowerShell console. PSReadLine highlights the syntax in the console, is responsible for selection of the text with your mouse and copying/pasting it using CTRL+C and CTRL+V.

The command history can be configured using Get-PSReadlineOption and Set-PSReadlineOption cmdlets. Current settings can be viewed using this command:

Get-PSReadlineOption | select HistoryNoDuplicates, MaximumHistoryCount, HistorySearchCursorMovesToEnd, HistorySearchCaseSensitive, HistorySavePath, HistorySaveStyle


The settings of the following parameters can be important for us:

HistoryNoDuplicates – determines whether the same commands have to be saved

MaximumHistoryCount –the maximum number of the stored commands

HistorySearchCursorMovesToEnd — determines whether you have to go to the end of the command when searching

HistorySearchCaseSensitive – determines whether search is case sensitive

HistorySavePath – shows the file the command history is stored

HistorySaveStyle – determines the peculiarities of saving commands:

  • SaveIncrementally — the commands are saved after they are run (by default)
  • SaveAtExit the history is saved when the console is closed
  • SaveNothing — disables saving command history

You can change the settings of PSReadLine module using Set-PSReadlineOption, for instance:

Set-PSReadlineOption -HistorySaveStyle SaveAtExit


So, the ability to save the history of PowerShell commands is one of the arguments to prefer PoSh 5.0 to cmd.

Related Articles