Windows 11: How to View Command History in PowerShell or Command Prompt

February 3, 2022 updated by Admin Leave a reply »

Is there a simple way to see Command Prompt history without using arrow keys? Can I view PowerShell command history for previous sessions? In this tutorial we’ll show you how to quickly access the history of commands you recently typed in Windows Terminal (PowerShell or Command Prompt).

Part 1: View Command History in PowerShell

When you’re at the PowerShell console, just run the history command and it will display all commands you typed during the current session.

By default, PowerShell maintains the command history of all sessions and store it in a text file located in your user profile directory. Just press the Windows key + R together to launch the Run dialog, copy and paste the following path and press Enter:

File Explorer will open to your specified location and you can see a text file named ConsoleHost_history.txt.

Open the ConsoleHost_history.txt file with NotePad and it reveals all the commands that you have typed in each PowerShell sessions.

Part 2: View Command History in Command Prompt

When you’re at the Command Prompt, just execute the below command and the command history for your current session will appear on the screen.
doskey /history

or press F7 key to open a pop-up inside the Command Prompt, which shows a list of the commands that have been entered in this session. You can use the up and down arrow keys to select a command, and then press Enter to execute the command again.

Once you close the Command Prompt window, the history will be removed permanently. Before closing it, you can use the following command to save the command history:
doskey /history > d:\MyHistory.txt

That’s it!