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...

How To Install Windows 11 on Unsupported Hardware

If you have a computer with unsupported hardware, you cannot upgrade to Windows 11 through Windows Update. However, Microsoft left a loophole open but made no official mention of it. He left this option to organizations and people who will knowingly install this system on incompatible hardware. To install you need to use a bootable USB drive or ISO file to manually install/update. Note that while Windows 11 can be installed on unsupported hardware, Microsoft is not obligated to provide security or driver updates. You do this at your own risk and there is no guarantee that your system will be stable and will have compatible drivers. As a reminder, when the hardware is incompatible, we will receive this information when installing the Win11 system: To install Windows 11 on an unsupported PC, use these steps: Start the PC with the Windows 11 USB Flash Drive Press any key to continue. Use the Shift + F10 keyboard shortcut to open Command...