Clear-History Powershell Doesnt Clear the History
PowerShell turns out has a great memory, and can help you with those tedious list of commands you've entered time over time. No worries if you've closed the PowerShell window, rebooted your machine, PowerShell will remember your history.
In most cases, that would be an awesome feature. However.... if you've ever tried to prep a VM, or otherwise tried to clear your history, perhaps a username and/or passowrd is in the list, you may wonder how to clear it.
You may find the Clear-History command. You may even run it. And, if you hit the up arrow, you'll find your history now includes the Clear-History command...
Hmmm
Well, if you want to clear the history, or actually pre-load the history with a list of commands to be used in a Lab VM, here's where you go:
%userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt
You can turn it off with:
Set-PSReadlineOption –HistorySaveStyle SaveNothing
Or point to a different location with:
Set-PSReadlineOption –HistorySavePath
And if you want to delete your history:
del (Get-PSReadlineOption).HistorySavePath
That's it...
Yet another thing that's really simple, once you know the answer...
Thanks to Jason Shirk from the PowerShell team
Steve
Comments
- Anonymous
April 02, 2016
Is the history file a feature of Windows 10, or a feature of PowerShell 5? I installed WMF 5 on Windows 7 (KB3134760), and even though PowerShell has been upgraded to version 5, I'm still finding no trace of the file, or its parent folder for that matter. - Anonymous
October 13, 2016
Set-PSReadlineOption –HistorySaveStyle SaveNothingDoesn't seem to do anything. Still writes to the file.