This is not obvious, but the Clear-History command in PowerShell won’t clear the history of the previous commands.
The Clear-History clears only the commands entered during the current session, that could be displayed by the Get-History command.
To clear the history in PowerShell, it needs to delete the file in which the previous commands are stored.
In this note i am showing how to locate the history file and how to clear the history of the PowerShell commands.
Cool Tip: PowerShell commands history file location! Read more →
Clear History in PowerShell
Get the PowerShell command history file location:
PS C:\> (Get-PSReadlineOption).HistorySavePath
Show the contents of the PowerShell command history file:
PS C:\> cat (Get-PSReadlineOption).HistorySavePath
Clear the command history in PowerShell by deleting the history file:
PS C:\> Remove-Item (Get-PSReadlineOption).HistorySavePath
Change how PowerShell command history is saved:
PS C:\> Set-PSReadlineOption -HistorySaveStyle SaveIncrementally # default PS C:\> Set-PSReadlineOption -HistorySaveStyle SaveAtExit PS C:\> Set-PSReadlineOption -HistorySaveStyle SaveNothing
This is elegant and simple. Thanks.
Excellent. Just what I was looking for.
very helpfull, thanks alot
Thanks
thanks
Remove-Item (Get-PSReadlineOption).HistorySavePath; Clear-History
deletes even the Remove-Item command 😉
I just want to delete the wrong command, opening the ConsoleHost_history.txt file to delete is not elegant
THANKSSS
Helpfull for me too
I did both of those commands, but hitting the up arrow still shows my previous commands. Is there any way to clear for the current session or must I close Powershell and start a new session to have a clear history?
Yes, close and open again
Take a bow. It worked beautifully. Straight, sweet and right to the point. Thanks.
How get the event in event viewer?
did not work
Thank you so much! First hint which is working. A charme.