Installing fonts with PDQD

Comments

24 comments

  • Stephen Valdinger

    Something like this should get you close:

     EDIT: Added registry bit

    Function Add-Fonts{
    Param(
    [cmdletBinding()]
    [parameter(Mandatory=$true,Position=0)]
    [string]$Source

    )


    $dest = 'C:\Windows\Fonts' #default font location
    $files = Get-ChildItem -Path $Source
    $Exclude = @()



    #Logic
    ForEach($file in $files){
    If (Test-Path "$dest\$file"){
    $Exclude += $file
    } #end if

    Copy-Item "$source\$file" -Destination $dest -Exclude $Exclude -Force

    $type = $file.Extension

    If($type -eq ".otf"){

    Set-Location 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'

    New-ItemProperty -Path . -Name "$($file.Name -replace ".{4}$") (OpenType)" -Type String -Value $file.name

    } #end type if

    ElseIf($type -eq ".ttf"){

    Set-Location 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts'

    New-ItemProperty -Path . -Name "$($file.Name -replace ".{4}$") (TrueType)" -Type String -Value $file.name

    } #end type elseif



    } #end foreach

    } #end function


    #Call file wtih ./Add-fonts.ps1 -Source <your source dir on the system>
    1
    Comment actions Permalink
  • Stephen Valdinger

    Here is the XML to copy/paste into a new xml file and then Import:

     

    <?xml version="1.0" encoding="utf-8"?>
    <AdminArsenal.Export Code="PDQDeploy" Name="PDQ Deploy" Version="12.1.0.7" MinimumVersion="9.0">
    <Package>
    <PackageDefinition name="Definition">
    <CopyMode>Default</CopyMode>
    <InventoryScanProfileId value="null" />
    <RunAs value="null" />
    <ScanAfterDeployment value="null" />
    <Steps type="list">
    <PowerShellStep>
    <CustomCommandLine></CustomCommandLine>
    <Files>\change\path\to\Add-fonts.ps1</Files>
    <Script>&amp; '.\Add-fonts.ps1' -Source "changeme"</Script>
    <SuccessCodes>0</SuccessCodes>
    <RunAs value="null" />
    <Conditions type="list">
    <PackageStepCondition>
    <Architecture>Both</Architecture>
    <Version>All</Version>
    <TypeName>OperatingSystem</TypeName>
    </PackageStepCondition>
    <PackageStepCondition>
    <IsUserLoggedOn>AlwaysRun</IsUserLoggedOn>
    <TypeName>LoggedOnUser</TypeName>
    </PackageStepCondition>
    </Conditions>
    <ErrorMode>StopDeploymentFail</ErrorMode>
    <IsEnabled value="true" />
    <Title>Copy fonts</Title>
    <TypeName>PowerShell</TypeName>
    </PowerShellStep>
    </Steps>
    <Timeout value="60" />
    <UseCustomTimeout value="false" />
    </PackageDefinition>
    <Description></Description>
    <FolderId value="null" />
    <Name>Add Fonts</Name>
    <Path>Add Fonts</Path>
    <Version></Version>
    <PackageDisplaySettings name="DisplaySettings">
    <DisplayType>Normal</DisplayType>
    <IconKey></IconKey>
    <SortOrder value="10" />
    </PackageDisplaySettings>
    </Package>
    </AdminArsenal.Export>
    1
    Comment actions Permalink
  • Emil Johansson

    Create a script called "ADD_Fonts.cmd", from the code below,  and put it in the same folder as the font files you want to be installed.
    Create a new "install package" and point to the ADD_Fonts.cmd. Check "Include entire directory".
    This is how I do it and it works fine here. :)

     

    @ECHO OFF
    TITLE Adding Fonts..
    REM Filename: ADD_Fonts.cmd
    REM Script to ADD TrueType and OpenType Fonts for Windows

    REM How to use:
    REM Place the batch file inside the folder of the font files OR:
    REM Optional Add source folder as parameter with ending backslash and dont use quotes, spaces are allowed
    REM example "ADD_fonts.cmd" C:\Folder 1\Folder 2\

    IF NOT "%*"=="" SET SRC=%*
    REM ECHO.
    REM ECHO Adding Fonts..
    REM ECHO.
    FOR /F %%i in ('dir /b "%SRC%*.*tf"') DO CALL :FONT %%i
    REM OPTIONAL REBOOT
    REM shutdown -r -f -t 10 -c "Reboot required for Fonts installation"
    REM ECHO.
    REM ECHO Done!
    REM PAUSE
    EXIT

    :FONT
    ECHO.
    REM ECHO FILE=%~f1
    SET FFILE=%~n1%~x1
    SET FNAME=%~n1
    SET FNAME=%FNAME:-= %
    IF "%~x1"==".otf" SET FTYPE=(OpenType)
    IF "%~x1"==".ttf" SET FTYPE=(TrueType)

    ECHO FILE=%FFILE%
    ECHO NAME=%FNAME%
    ECHO TYPE=%FTYPE%

    COPY /Y "%SRC%%~n1%~x1" "%SystemRoot%\Fonts\"
    reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%FNAME% %FTYPE%" /t REG_SZ /d "%FFILE%" /f
    GOTO :EOF

    0
    Comment actions Permalink
  • Pushpak Patil

    Thanks Emil :)

    0
    Comment actions Permalink
  • John Hallford

    Emil,

    If I create a folder for a user and set it up as you instructed above so that the schedule runs once a day, that would allow the user to drop fonts into the folder as needed. That begs a question. Do you know what will happen when the script runs and how it will handle trying to install a font that already exists? I can set up a test machine but thought you may already know the answer. Thank you.

    0
    Comment actions Permalink
  • Stephen Valdinger

    John,

     

    We could refactor her code into Powershell so we could add some error handling to allow for skipping duplicates.

    0
    Comment actions Permalink
  • John Hallford

    I wouldn't know where to begin, as programming is outside of my expertise. I can always have her manually manage the folder, but if there is a way to deal with duplicates that would be so much easier.

    0
    Comment actions Permalink
  • Stephen Valdinger

    Thats where I come in. Give me a minute. I'll post the Powershell alternative.

    0
    Comment actions Permalink
  • John Hallford

    Stephen,

    I will be watching for it and thank you in advance for your help with this matter. Very much appreciated.

    0
    Comment actions Permalink
  • Stephen Valdinger

    Sorry that is poorly formatted. It's stripping off my line indents for some reason, so it kind of makes it hard to follow.

    0
    Comment actions Permalink
  • John Hallford

    Stephen,

    Thank you for setting this up. Is this copied to Notepad and saved as a .BAT file or something else?

    0
    Comment actions Permalink
  • Stephen Valdinger

     

    Give me just one more second. I just re-read the file and it looks like the are using reg add to inject the registry with the font, which I didn't do in my script. I will add that step, and edit my post above with the new code. I will also be creating a secondary comment here shortly with a package xml that you can save as an xml file and import into your PDQ Deploy console so your package is all setup and ready to go. You'll just have to edit  the Powershell step and change 'changeme' to the actual path you create for the user to dump fonts too.

    0
    Comment actions Permalink
  • John Hallford

    Stephen,

    You are amazing. Thank you again for taking the time to put this together. I'll give it a good test run and follow up here.

    0
    Comment actions Permalink
  • Stephen Valdinger

    That would be good. I sort of tested it a little bit in chunks as I went, mostly to make sure I was putting the right data together, but I didn't test it in its entirety as a script or try to deploy it. Please let me know if you get any red text from the powershell, and post it here so I can have a look and fix it.

    0
    Comment actions Permalink
  • John Hallford

    Will do. Have a great weekend.

    0
    Comment actions Permalink
  • Pushpak Patil

    Found a Alternative....

    FontReg.exe

    http://code.kliu.org/misc/fontreg/ 

     

    You need to use fontreg.exe /copy it will install all fonts within the directory and add a reg entry. (Reboot Required)

     

    Regards,

    Pushpak

    0
    Comment actions Permalink
  • John Hallford

    Pushpak,

    Thanks for the alternative. If I cannot get the solution provided by Stephen to work then I will try it.

     

    Stephen,

    I copied the script, pasted to Notepad, saved it as an XML, and imported it into PDQ Deploy. I changed the source and verified the path in Step 1. When deployed it failed with the status message, "Not Found - Failed to read file on source." I went back, verified the path, and verified permissions. The Deploy User has rights to the directory and the path is correct.

    Is "Add-fonts.ps1" a pre-existing utility in PDQ Deploy or on the Windows server? It seems that it is being called from \\TUSCPDQ\PDQ\Powershell, and since that does not exist on our network I am guessing that is part if not all of the issue here. Will you let me know what I need to do here? 

    Much appreciated.

    0
    Comment actions Permalink
  • Stephen Valdinger

    You'll want to change the Files to something other than TUSCPDQ. That's the name of my development box for staging changes to my PDQ environment.

     

    You'll want to put it wherever you find easiest to get to. For me, in DEV, that is in the folder mentioned above, but is entirely different from your environment. Use the ... button to browse for and find your copy of Add-fonts.ps1. The field will update itself accordingly.

    0
    Comment actions Permalink
  • Stephen Valdinger

    I edited my XML above to better reflect that for anyone else stumbling in here from a Google Search.

    0
    Comment actions Permalink
  • John Hallford

    I guess I am not quite sure where the file "Add-fonts.ps1" comes from. I searched the PDQ Server and did not find it. Is that a file you sent to me and I have overlooked it?

    0
    Comment actions Permalink
  • Stephen Valdinger

    You have to create it yourself from the Powershell code I posted above.

    0
    Comment actions Permalink
  • John Hallford

    I figured out my confusion. I thought the first set of code you sent was replaced with the XML file. I now realize I need both. The first set of code is the Add-fonts.ps1 and the second was to facilitate the creation of the package in PDQ D. Sorry to be a tad slow on this.

    0
    Comment actions Permalink
  • Jean Davis

    Here is my font script for PDQ. It works great for Windows 10 & 7. I have a schedule set to install on any machines found in an AD group. The helpdesk then just has to add the machine in the group.

    1. Copy fonts to C:\windows\fonts
    2. command prompt -

    @ECHO OFF

    REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "Solitas Normal Book (OpenType)" /t REG_SZ /d "Solitas-NormBook.otf"

    EXIT

    0
    Comment actions Permalink
  • Munikanth Polepalli

    C:\Folder 1\Folder 2\ 

    What I have Keep  Here

    0
    Comment actions Permalink

Please sign in to leave a comment.