Skip to content

Instantly share code, notes, and snippets.

@ChrisColeTech
Last active August 17, 2025 16:59
Show Gist options
  • Select an option

  • Save ChrisColeTech/c7c8d4fb8f8e72ac01722cb5d5ce79f9 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisColeTech/c7c8d4fb8f8e72ac01722cb5d5ce79f9 to your computer and use it in GitHub Desktop.
Windows Toast Notification Uninstaller - PowerShell script (Unicode fixed)
# Windows Toast Notification Uninstaller
# This script removes toast notification setup from Windows
# Usage: Run this script in PowerShell
param(
[switch]$Force = $false
)
# Function to write colored output
function Write-ColorOutput($ForegroundColor) {
$fc = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $ForegroundColor
if ($args) {
Write-Output $args
} else {
$input | Write-Output
}
$host.UI.RawUI.ForegroundColor = $fc
}
Write-ColorOutput Yellow "=== Windows Toast Notification Uninstaller ==="
Write-Output ""
$binDir = "C:\ProgramData\Toast"
$toastPs1Path = Join-Path $binDir "toast.ps1"
$toastCmdPath = Join-Path $binDir "toast.cmd"
# Remove toast scripts
if (Test-Path $toastPs1Path) {
Write-Output "Removing PowerShell script: $toastPs1Path"
Remove-Item $toastPs1Path -Force
} else {
Write-Output "PowerShell script not found: $toastPs1Path"
}
if (Test-Path $toastCmdPath) {
Write-Output "Removing CMD wrapper: $toastCmdPath"
Remove-Item $toastCmdPath -Force
} else {
Write-Output "CMD wrapper not found: $toastCmdPath"
}
# Remove bin directory from PATH
$currentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($currentPath -like "*$binDir*") {
Write-Output "Removing $binDir from user PATH..."
$pathEntries = $currentPath -split ';' | Where-Object { $_ -ne $binDir -and $_ -ne "" }
$newPath = $pathEntries -join ';'
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
} else {
Write-Output "Bin directory not found in PATH"
}
# Remove empty toast directory if no other files
if (Test-Path $binDir) {
$binContents = Get-ChildItem $binDir -Force
if ($binContents.Count -eq 0) {
Write-Output "Removing empty toast directory: $binDir"
Remove-Item $binDir -Force
} else {
Write-Output "Toast directory contains other files, not removing: $binDir"
$binContents | ForEach-Object { Write-Output " - $($_.Name)" }
}
}
# Clean PowerShell profile
$profilePath = $PROFILE.CurrentUserAllHosts
if (Test-Path $profilePath) {
$profileContent = Get-Content $profilePath -Raw
# Look for toast notification section
$startPattern = "# Toast notification functions"
$endPattern = "Set-Alias -Name t -Value Show-Toast"
if ($profileContent -like "*$startPattern*") {
Write-Output "Removing toast functions from PowerShell profile: $profilePath"
# Split content into lines for processing
$lines = Get-Content $profilePath
$newLines = @()
$inToastSection = $false
$skipNextLine = $false
foreach ($line in $lines) {
if ($skipNextLine) {
# Skip the closing brace after the toast section
if ($line -match '^\s*\}\s*$') {
$skipNextLine = $false
continue
}
$skipNextLine = $false
}
if ($line -like "*$startPattern*") {
$inToastSection = $true
continue
}
if ($inToastSection -and $line -like "*$endPattern*") {
$inToastSection = $false
$skipNextLine = $true # Skip the closing brace on next iteration
continue
}
if (-not $inToastSection) {
$newLines += $line
}
}
# Remove trailing empty lines
while ($newLines.Count -gt 0 -and [string]::IsNullOrWhiteSpace($newLines[-1])) {
$newLines = $newLines[0..($newLines.Count - 2)]
}
if ($newLines.Count -eq 0) {
Write-Output "PowerShell profile is now empty, removing: $profilePath"
Remove-Item $profilePath -Force
} else {
Set-Content -Path $profilePath -Value $newLines -Encoding UTF8
}
} else {
Write-Output "Toast functions not found in PowerShell profile"
}
} else {
Write-Output "PowerShell profile not found: $profilePath"
}
# Optionally remove BurntToast module
if ($Force) {
Write-Output "Removing BurntToast module..."
try {
Uninstall-Module -Name BurntToast -Force -ErrorAction Stop
Write-ColorOutput Green "[SUCCESS] BurntToast module removed"
} catch {
Write-Output "BurntToast module not found or couldn't be removed: $_"
}
} else {
Write-Output ""
Write-Output "Note: BurntToast PowerShell module was not removed."
Write-Output "To remove it, run: Uninstall-Module -Name BurntToast -Force"
Write-Output "Or re-run this script with -Force parameter"
}
Write-Output ""
Write-ColorOutput Green "Uninstall complete!"
Write-Output ""
Write-Output "You may need to restart your terminal for PATH changes to take effect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment