How to view command history from previous PowerShell sessions in Windows 10

In this tutorial, TipsMake will show you how to view the entire command history from all previous sessions in Windows 10.

Is there a way to see the command line history on all PowerShell sessions? Windows PowerShell allows you to see every command you have executed in the current session by using the Get-History command . But sometimes that is not enough. In this tutorial, TipsMake will show you how to view the entire command history from all previous sessions in Windows 10.

How to view command history from previous PowerShell sessions in Windows 10

1. To use the PowerShell command history view function, you first need to install the PSReadLine module with the command below.

Install-Module PSReadLine
How to view command history from previous PowerShell sessions in Windows 10 Picture 1 To use the PowerShell command history view function, you first need to install the PSReadLine module

If you are prompted to install the NuGet Provider , enter Yand press Enter.

2. Next, enter the following command to display the path to the file in which the PowerShell command history is saved.

(Get-PSReadlineOption).HistorySavePath
How to view command history from previous PowerShell sessions in Windows 10 Picture 2 Shows the path to the file in which the PowerShell command history is stored

3. To view the detailed command history on the PowerShell console, run this command:

cat (Get-PSReadlineOption).HistorySavePath

4. To delete all the history of PowerShell commands that you have entered, type the following command:

Remove-Item (Get-PSReadlineOption).HistorySavePath
How to view command history from previous PowerShell sessions in Windows 10 Picture 3 The command clears all the history of PowerShell commands that you have entered

5. If you need to prevent PowerShell from saving command history, execute this command:

Set-PSReadlineOption -HistorySaveStyle SaveNothing
How to view command history from previous PowerShell sessions in Windows 10 Picture 4 The command prevents PowerShell from saving command history

6. Whenever you want to configure PowerShell to keep track of all the commands you have executed, run the following command:

Set-PSReadlineOption -HistorySaveStyle SaveIncrementally

Above are the commands you can use to control the history of the commands used in Powershell.

Hope you are succesful.

« PREV POST
NEXT POST »