See the Command History Across All PowerShell Sessions

Rohan Timalsina Jan 31, 2022
See the Command History Across All PowerShell Sessions

PowerShell maintains a history of each session. PowerShell’s Get-History cmdlet lists all commands entered during the current session.

The $MaximumHistoryCount variable determines the number of entries in the session history. The default value is 4096.

It shows each command and its ID, which indicates the order in which they are executed.



  Id CommandLine
  -- -----------
   1 Get-Date
   2 Get-ChildItem
   3 Get-Content test.txt
   4 Get-Command gcc

The Get-History displays the previous commands entered in the current session only.

By default, PowerShell stores the command history of all sessions in a text file located in a user’s home directory. This tutorial will teach you to see the command history across all PowerShell sessions.

Use the (Get-PSReadlineOption).HistorySavePath to See the Command History Across All PowerShell Sessions

The following command prints the path of a file where the command history is saved.




You can use the Get-Content cmdlet to list all the contents saved in that file.

Get-Content (Get-PSReadlineOption).HistorySavePath


Get-Content C:\Users\rhntm\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

Both commands will print the long list of commands on the console executed previously across all PowerShell sessions.

Here is a short overview of the output.


date = Get-Date -format "yyyyMMdd"
$date = Get-Date -format "yyyyMMdd"
$dateStr = $date -format "yyyyMMdd"
$dateStr = date -format "yyyyMMdd"

You can also open the file in text editors like notepad and view the command history.

notepad (Get-PSReadlineOption).HistorySavePath


see the command history across all powershell sessions

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website