Skip to main content

PowerShell Permanently Clear History

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

Popular posts from this blog

How to use Test-NetConnection in PowerShell

In the latest versions of Windows, the client and telnet service are not installed by default. They are available as installable functions. Unfortunately, turning on telnet often requires a restart computer. The connection test can be performed with the ping command, but does not perform any tracing or port testing. In most network problems we need to use ping command with tracert. Also telnet for check for open ports. PowerShell Test-NetConnection The Test-NetConnection command is the successor to Test-Connection but provides more information. Let's do a simple test to Google: PS C:\> Test-NetConnection 8.8.8.8 ComputerName : 8.8.8.8 RemoteAddress : 8.8.8.8 InterfaceAlias : Ethernet 2 SourceAddress : 192.168.1.10 PingSucceeded : True PingReplyDetails (RTT) : 9 ms The command returns a lot of information, usually this is enough to find a network problem (if any). It will display the interface, source I...

Keyboard Shortcut for Part or Full Screenshot

Windows 10 has a built-in screenshot tool. You can take a screenshot of the full screen or just a part of it. The screenshots will be copied to the clipboard so you can paste into any program that supports images like Paint, Photoshop, messengers like MS Teams or email messages.  Keyboard Shortcut Press Winkey + Shift + S . The screen will have a light or dark overlay and the mouse cursor will change to a plus (+) symbol, which means capture mode is on. A bar will appear at the top of the main screen. From there, you can choose one of the snipping modes: Rectangular  - take a rectangular screenshot by dragging the desired fragment with the cursor. Freeform  - freely create a screenshot of a non-standard shape by "painting" with the pressed cursor. Window  - captures part of the screen, e.g. a window on the screen, such as browser window, file explorer window, etc. Fullcreen  - captures ...