Skip to content

Instantly share code, notes, and snippets.

@Paldom
Created December 28, 2015 13:44

Revisions

  1. Paldom created this gist Dec 28, 2015.
    33 changes: 33 additions & 0 deletions gfonts.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ## gfonts.ps1 ##

    <#
    .SYNOPSIS
    Script that installs ttf fonts from subfolders recursively, e.g. for batch Google Font install
    .NOTES
    File Name: gfonts.ps1
    Author: Domonkos Pal - [email protected]
    License: MIT
    #>

    # http://stackoverflow.com/questions/16023238/installing-system-font-with-powershell
    function InstallFont ($loc) {
    $FONTS = 0x14
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)
    $objFolder.CopyHere($loc)
    }

    function DfsFontInstall ($dir) {
    foreach($file in Get-ChildItem $dir) {
    if($file.Attributes -ne 'Directory') {
    if ($file.Extension -eq '.ttf') {
    InstallFont $file.FullName;
    Write-Output "Font $($file.Name) has been installed.";
    }
    } else {
    DfsFontInstall $file.FullName;
    }
    }
    }

    DfsFontInstall;