How to Safely Extract Windows 11 ‘PowerShell Command History’ (Find Forgotten Scripts)

If you are a system administrator, you likely use Windows PowerShell to run complex scripts to manage servers or automate backups. If you crafted a perfectly optimized, 5-line command three months ago but forgot to save it in a `.ps1` script file, you might assume it’s lost forever.

Unlike the traditional Command Prompt (which wipes its memory the second you close the window), modern Windows PowerShell actively maintains a hidden text log of every single command you have ever typed. You can safely extract this entire chronological history file to recover your forgotten scripts.

How to Safely Extract Windows 11 PowerShell Command History

You must locate the hidden `ConsoleHost_history.txt` file within your AppData directory.

  1. Open File Explorer (press Windows Key + E).
  2. Click inside the main address bar at the top of the window.
  3. To navigate directly to the hidden PowerShell history folder, copy and paste this exact path and press Enter: %APPDATA%\Microsoft\Windows\PowerShell\PSReadLine
  4. Inside this folder, you will see a single text file named ConsoleHost_history.txt.
  5. Right-click the file, select Copy, and Paste it onto your Desktop to ensure you don’t accidentally modify the active log.
  6. Double-click the copied file on your Desktop. It will open in Notepad.

You are now looking at a raw text dump of every PowerShell command you have executed. Because this list can be thousands of lines long, press Ctrl + F to open the Find tool. Type a specific keyword you remember from your lost command (like “Get-Process” or “Export-CSV”) to instantly jump to the exact script you need to recover.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.