Search This Blog

Tuesday, August 4, 2026

Install 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 {
        # Skip if already present
        if (Test-Path $destFile) {
            continue
        }

        # 1. Copy font file
        Copy-Item -Path $font.FullName -Destination $destFile -Force -ErrorAction Stop

        # 2. Register in registry
        if (-not (Get-ItemProperty -Path $RegPath -Name $regName -ErrorAction SilentlyContinue)) {
            New-ItemProperty -Path $RegPath -Name $regName -Value $font.Name -PropertyType String -Force | Out-Null
        }
	}
	catch {
	}
}

exit 0

No comments: