The topic Every command you’ve pasted into PowerShell is still sitting in a text file on… is drawing steady attention: readers, analysts, and industry watchers are all tracking how the story may unfold in the days ahead.
This is taking place in a fast-moving context — product cycles, platform shifts, and competitive moves can reshape the outlook quickly, so the details below are worth a careful read.
What follows is a clear walkthrough of the main facts and angles you need to make sense of the news.
If you use PowerShell to automate tasks on your PC and need to reuse a command, you can press the Up and Down arrow keys to cycle through the last few. But what if you want to go back to a command you typed a month ago? Microsoft thought of that too, so PowerShell saves your command history in a plain text file. It’s convenient, but it also comes with a security risk that deserves your attention.
This PowerShell script does a few things your PC manufacturer or Microsoft doesn’t want to be done!
PowerShell keeps two separate history logs. The first is the built-in session history, which tracks the commands you run in the current window. It’s what Get-History shows you, and it’s cleared the moment the session ends and you close the window. By default, it holds up to 4,096 commands and starts dropping the oldest ones as you add more.
The second is the persistent history kept by PSReadLine, the module that handles typing, editing, and command recall in the PowerShell console. If you’re on Windows PowerShell 5.1, which comes with Windows 10 and 11, or PowerShell 7, every command you type gets written to a plain text file on your drive. That’s why pressing the Up arrow in a brand new window can still bring back a command from last week.

You don’t need to remember that path. Run this in PowerShell, and it prints every command from your past sessions:
To open it in Notepad instead, press Win + R, paste the path above into the Run dialog, and hit OK. Pasting it into the File Explorer address bar works too, and %APPDATA% takes you straight past the hidden AppData folder.
If you’ve used PowerShell for a while, expect a long scroll. PSReadLine only loads the most recent 4,096 entries for Up arrow recall, but nothing trims the file itself. It keeps growing from the very first command you ran in that console.
The history file can’t tell the difference between Get-Process and a password. On Windows PowerShell 5.1, whatever you type or paste into the console gets saved as is. That includes the API key you pasted to test an endpoint, a GitHub personal access token inside a git clone URL, a database connection string with the password baked in, or a quick net user bob P@ssw0rd /add to create a local account.
The file isn’t encrypted, and it isn’t locked away. Any program running under your account can read it, and so can an admin. That’s exactly why attackers go looking for it. MITRE, which keeps a public catalog of attacker techniques, lists shell history as a known place to find credentials and calls out PowerShell’s persistent history by name.
How exposed you are depends on your PowerShell version. Windows PowerShell 5.1 still ships with an old copy of PSReadLine that has no filter, so unless you’ve updated the module, everything goes into the file. Newer PSReadLine releases, which come with PowerShell 7, skip any line containing password, asplaintext, token, apikey, or secret. A command like ConvertTo-SecureString’ hunter2′ -AsPlainText -Force stays in session memory but never reaches the file.
The catch is that the filter only looks for those words. A secret passed without them slips right through. The net usercommand above, curl -u admin:P@ssw0rd, or a key pasted as a bare argument still gets saved, even on PowerShell 7. And while Microsoft recently announced that PowerShell 7 will ship with the next Windows release, 5.1 will stay installed alongside it, so the unfiltered version isn’t going anywhere soon.

The obvious fix is Clear-History, but it doesn’t touch the file. It only empties the session list that Get-History shows. Close the window, open a new one, press the Up arrow, and your old commands are still there.
PSReadLine creates a fresh file the next time you run a command. Keep in mind that each host keeps its own file, so if you use the PowerShell terminal in VS Code, there’s a separate Visual Studio Code Host_history.txt in the same folder to clean up.
That’s a heavy trade-off, though, since you lose Up arrow recall across sessions. A better middle ground is a custom AddToHistoryHandler, which decides line by line what gets written to history:
Commands that match the pattern are skipped, and everything else is saved as usual, so you keep Up arrow recall for your everyday commands. Add the tools you use to the pattern. On PowerShell 7, you can return ‘MemoryOnly’ instead of $false for matching lines if you still want them available in the current window.
It comes with a quirk, though. A custom handler replaces PSReadLine’s default filter instead of adding to it, which is why the pattern above repeats the original keywords. Leave them out, and PowerShell 7 goes back to saving everything.
Both settings also last only for the current session. To make them stick, run notepad $PROFILE, paste the command, and save. If the profile doesn’t exist yet, create it first with New-Item -Path $PROFILE -Force.
PowerShell’s persistent history is a handy feature, and something I’ve relied on since I discovered it had one. Because it’s plain text, you can search it like any other file.
However, to reduce the security risk, you need to keep secrets out of the terminal, either with the SecretManagement module, whose Get-Secret commands the filter is built to allow, or a free password manager like Bitwarden. The file can remember everything you want, as long as there’s nothing in it worth stealing.