Quicktip: PowerShell command history on Windows 10 using PSReadline

In Windows 10 PowerShell 5.0 comes bundled with PSReadline. This module allows for a number of useful features and today we will focus on getting access to the command history. A very useful feature of PSReadline is that it writes the history of PowerShell commands to a text file and this text file is easily accessible. The path where this file is stored can be found by executing the following command:

1
(Get-PSReadlineOption).HistorySavePath

PSReadLine

To view the list of previously executed commands you can type the following:

1
Get-Content -Path (Get-PSReadlineOption).HistorySavePath

This will output the contents of the history file to your PowerShell console. Alternatively the file can be opened by your favorite editor by using the Invoke-Item cmdlet:

1
Invoke-Item -Path (Get-PSReadlineOption).HistorySavePath

A very useful feature if you accidentally closed your console without saving your command history.

Share

Leave a Reply

Your email address will not be published.