PowerShell has a command to clear the command history like Clear-History. However, it is independent of the host and must be deleted separately. This information is especially important when you need to use a command with your password (in command).
How to permanently delete PowerShell history?
The entire history of the commands you use in PowerShell is saved to one file.
To fully delete the history, all you need to do is ... delete the file.
Usually the file is located in AppData, but you can check the exact path with
the command which will display the full path.
PS C:\> (Get-PSReadlineOption).HistorySavePath
### result
C:\Users\geekitsupp\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
After deleting this file, all history of commands executed in PowerShell will be
deleted.
Clear-History or
[Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory()
command doesn't permanently delete history. They can only delete history in
the session you are working on. After closing the session and restarting
PowerShell, the history will be available in the console.
How to delete history more easier?
You can go to the appropriate folder and delete the command history file yourself. However, you can do it a bit faster by simply replacing this file with a new empty file by command.
PS C:\> New-Item -Path (Get-PSReadlineOption).HistorySavePath -Force
### result
Directory: C:\Users\geekitsupp\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 10.07.2022 12:00 0 ConsoleHost_history.txt
Comments
Post a Comment