Released Nov 25, 2026, 4:00 PM EST
With hands-on experience structure sites and innovation blog sites, he brings useful designer insights to his technical writing. You can see his total work portfolio at itashreef.com.
You may likewise come across his brief how-to video explainers, streamlining intricate subjects. Beyond composing, Tashreef delights in producing brief explainer videos, video gaming, and checking out animated programs.
If you utilize PowerShell to automate jobs on your PC and require to recycle a command, you can push the Up and Down arrow secrets to cycle through the last couple of. What if you desire to go back to a command you typed a month back? Microsoft thought about that too, so PowerShell conserves your command history in a plain text file. It’s practical, however it likewise features a security danger that deserves your attention.
PowerShell always remembers a command
Your history resides in a plain text file
PowerShell keeps 2 different history logs. The very first is the integrated session history, which tracks the commands you run in the existing window. It’s what Get-History reveals you, and it’s cleared the minute the session ends and you close the window. By default, it holds up to 4,096 commands and begins dropping the earliest ones as you include more.
<p>The 2nd is the consistent history kept by <a href="https://github.com/PowerShell/PSReadLine" target="_blank">PSReadLine</a>the module that deals with typing, modifying, and command recall in the PowerShell console. If you're on Windows PowerShell 5.1, which features Windows 10 and 11, or PowerShell 7, every command you type gets composed to a plain text file on your drive. That's why pushing the Up arrow in a brand name brand-new window can still revive a command from recently.</p> <p>On Windows, the file lives here:</p>
%APPDATA%MicrosoftWindowsPowerShellPSReadLineConsoleHost_history.txt
You do not require to keep in mind that course. Run this in PowerShell, and it prints every command from your previous sessions:
Get-Content (Get-PSReadLineOption).HistorySavePath
To open it in Notepad rather, press Win + Rpaste the course above into the Run dialog, and struck OKAYPasting it into the Submit Explorer address bar works too, and %APPDATA% takes you straight past the surprise AppData folder.
<p>If you've utilized PowerShell for a while, anticipate a long scroll. PSReadLine just loads the most current 4,096 entries for Up arrow recall, however absolutely nothing cuts the file itself. It keeps growing from the really first command you ran in that console.</p> PowerShell shops more than simply commands
Tricks you paste wind up in the file too
<figure><picture>
</picture></figure>
The history file can’t discriminate in between Get-Process and a password. On Windows PowerShell 5.1, whatever you type or paste into the console gets conserved as is. That consists of the API secret you pasted to check an endpoint, a GitHub individual gain access to token inside a git clone URL, a database connection string with the password baked in, or a fast net user bob P@ssw0rd /add to produce a regional account.
<p>The file isn't secured, and it isn't locked away. Any program running under your account can read it, therefore can an admin. That's precisely why enemies go searching for it. MITRE, which keeps a public brochure of opponent methods, lists shell history as a recognized location to discover qualifications and calls out PowerShell's consistent history by name.</p> <p>How exposed you are depends upon your PowerShell variation. Windows PowerShell 5.1 still ships with an old copy of PSReadLine that has no filter, so unless you've upgraded the module, whatever enters into the file. More recent PSReadLine releases, which include PowerShell 7, avoid any line consisting of password, asplaintext, token, apikey, or trick. A command like <code>ConvertTo-SecureString' hunter2' -AsPlainText -Force</code> remain in session memory however never ever reaches the file.</p> <p>The catch is that the filter just tries to find those words. A secret passed without them slips right through. The <code>net usercommand above, curl -u admin:P@ssw0rd</code>or a crucial pasted as a bare argument still gets conserved, even on PowerShell 7. And while Microsoft just recently revealed that PowerShell 7 will deliver with the next Windows release, 5.1 will remain set up along with it, so the unfiltered variation isn't going anywhere quickly.</p> Clear history does not assist
Erase the file and alter what gets conserved
<figure><picture>
</picture></figure>
The apparent repair is Clear-History, however it does not touch the file. It just clears the session list that Get-History programs. Close the window, open a brand-new one, press the Up arrow, and your old commands are still there.
<p>To clean the file, erase it straight:</p>
Remove-Item (Get-PSReadLineOption).HistorySavePath
PSReadLine develops a fresh file the next time you run a command. Each host keeps its own file, so if you utilize the PowerShell terminal in VS Code, there’s a different Visual Studio Code Host_history. txt in the very same folder to tidy up.
<p>If you 'd rather not keep a history file at all, you can turn it off:</p> <p>Set-PSReadLineOption -HistorySaveStyle SaveNothing</p> <p>That's a heavy compromise, however, given that you lose Up arrow recall throughout sessions. A much better happy medium is a customized AddToHistoryHandler, which chooses line by line what gets composed to history:</p>
Set-PSReadLineOption -AddToHistoryHandler {
param($line)
$sensitive='password|asplaintext|token|apikey|secret|net user|curl.*-u '
return ($line -notmatch $sensitive)
}
Commands that match the pattern are avoided, and whatever else is conserved as typical, so you maintain arrow recall for your daily commands. Include the tools you utilize to the pattern. On PowerShell 7, you can return ‘MemoryOnly’ rather of $incorrect for matching lines if you still desire them offered in the present window.
It comes with a peculiarity. A customized handler changes PSReadLine’s default filter rather of contributing to it, which is why the pattern above repeats the initial keywords. Leave them out, and PowerShell 7 returns to conserving whatever.
<p>Both settings likewise last just for the present session. To make them stick, run <code>notepad $PROFILE</code>paste the command, and conserve. If the profile does not exist yet, produce it initially with <code>New-Item -Path $PROFILE -Force</code></p> Your history deserves keeping, simply not with tricks in it
PowerShell’s relentless history is a useful function, and something I’ve counted on given that I found it had one. Since it’s plain text, you can browse it like any other file.
<p>To minimize the security danger, you require to keep tricks out of the terminal, either with the SecretManagement module, whose Get-Secret commands the filter is constructed to permit, or a totally free password supervisor like Bitwarden. The file can keep in mind whatever you desire, as long as there's absolutely nothing in it worth taking.</p>
Discover more from PMN S.P.O.R.T.S - A PRIME MEDIA NETWORK BRAND
Subscribe to get the latest posts sent to your email.





