Search This Blog

Tuesday, August 4, 2026

Uninstall Fonts Script


param (
    [string]$SourcePath = $PSScriptRoot
)

$FontsFolder = "$env:windir\Fonts"
$RegPath     = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"

if (-not (Test-Path -Path $SourcePath -PathType Container)) {
    exit 1
}

$fonts = Get-ChildItem -Path $SourcePath -Filter "*.ttf" -Recurse -File -ErrorAction SilentlyContinue

if ($fonts.Count -eq 0) {
    exit 0
}

foreach ($font in $fonts) {
    $destFile = Join-Path $FontsFolder $font.Name
    $regName  = "$($font.BaseName) (TrueType)"

    try {
        # 1. Remove registry entry
        if (Get-ItemProperty -Path $RegPath -Name $regName -ErrorAction SilentlyContinue) {
            Remove-ItemProperty -Path $RegPath -Name $regName -Force -ErrorAction Stop
        }

        # 2. Delete font file
        if (Test-Path $destFile) {
            Remove-Item -Path $destFile -Force -ErrorAction Stop
        }
    }
    catch {
    }
}

exit 0

No comments: