Created
October 19, 2025 23:55
-
-
Save LinkPhoenix/98fe4c74f64af96d05943c2ec9ff7be6 to your computer and use it in GitHub Desktop.
Clear the PSReadLine history file used by PowerShell 7 and Oh My Posh without deleting the file, preserving permissions. Provides simple, colored console output to confirm actions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| .SYNOPSIS | |
| Clear PowerShell 7 and Oh My Posh PSReadLine history without deleting history file. | |
| .DESCRIPTION | |
| This script empties the PSReadLine history file used by PowerShell 7 and Oh My Posh | |
| prompts, keeping the file intact to preserve permissions. | |
| Useful for removing command history while maintaining configuration integrity. | |
| .PARAMETER None | |
| No parameters required; script runs with an interactive log output. | |
| .EXAMPLE | |
| .\Clear-PS7-OhMyPoshHistory.ps1 | |
| Empties the PSReadLine history file for current user session. | |
| .NOTES | |
| Created: 2025-10-20 | |
| Author: LinkPhoenix | |
| Version: 1.0 | |
| #> | |
| # Path to PSReadLine history | |
| $historyPath = Join-Path $env:APPDATA 'Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt' | |
| # Function for colored output | |
| function Write-Log { | |
| param ( | |
| [string]$Message, | |
| [ConsoleColor]$Color = 'White' | |
| ) | |
| $prev = $Host.UI.RawUI.ForegroundColor | |
| $Host.UI.RawUI.ForegroundColor = $Color | |
| Write-Host $Message | |
| $Host.UI.RawUI.ForegroundColor = $prev | |
| } | |
| Write-Log "`n=======================================" Cyan | |
| Write-Log " PS7 & Oh My Posh History Cleaner" Cyan | |
| Write-Log "=======================================`n" Cyan | |
| if (Test-Path $historyPath) { | |
| Write-Log "[✓] Found history file at $historyPath" Green | |
| try { | |
| Clear-Content -Path $historyPath -ErrorAction Stop | |
| Write-Log "[✓] Emptied PSReadLine history file" Green | |
| } catch { | |
| Write-Log "[✗] Failed to clear history file: $_" Red | |
| } | |
| } else { | |
| Write-Log "[i] No PSReadLine history file found" Yellow | |
| } | |
| Write-Log "`n[✓] Cleanup completed`n" Cyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment