Posts Tagged ‘powershell history command’

How to See Command History from Previous PowerShell Sessions in Windows 10

March 15th, 2020 by Admin

Is there a way to see command line history across all PowerShell sessions? Windows PowerShell lets you view every command you’ve executed during the current session by using the Get-History command. But sometimes that is not enough. In this tutorial we’ll show you how to see the full command history from all previous sessions in Windows 10.

How to See Command History from Previous PowerShell Sessions in Windows 10

  1. In order to use the PowerShell command history functionality, you need to first install the PSReadLine module with the below command.
    Install-Module PSReadLine

    If you’re prompted to install NuGet Provider, type Y and press Enter.

  2. Next, type the following command to display the path to the file in which the PowerShell command history is saved.
    (Get-PSReadlineOption).HistorySavePath

    To view the full detailed command history on the PowerShell console, run this command:
    cat (Get-PSReadlineOption).HistorySavePath

  3. To clear all the history of PowerShell commands you’ve ever typed, type the following command:
    Remove-Item (Get-PSReadlineOption).HistorySavePath

    If you need to prevent PowerShell from saving command history, execute this command:
    Set-PSReadlineOption -HistorySaveStyle SaveNothing

    Whenever you want to configure PowerShell to track all executed commands again, run the following command:
    Set-PSReadlineOption -HistorySaveStyle SaveIncrementally

That’s it!