Newbie help - PowerShell script to install fonts

Welcome Forums General PowerShell Q&A Newbie help - PowerShell script to install fonts

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
3 weeks, 6 days ago.

  • Author
    Posts
  • #145983

    Participant
    Points: 13
    Rank: Member

    First off, Im a complete Newbie to powershell.

    I am working on a project where i need to install a number of fonts from a specific folder, already placed locally on receiving computer. The Font folder has subfolders, containing yet more fonts.

    Im trying to automate this process in a script, but no matter what i have tried nothing seems to work. I have full admin rights, and can do it manually – no problem there.

    Can some help me get started on this problem... Google Searching gave me a bunch of scripts, but none work for me and i am not well enough versed in powershell to edit them yet.

  • #146018

    Participant
    Points: 1,368
    Helping Hand
    Rank: Community Hero

    Rasmus,

    welcome to Powershell.org. So you already searched for it ... great. 😉 What have you tried so far and why didn't it workout for you? Did you try to find something on the PowershellGallery?

  • #146120
    js

    Participant
    Points: 956
    Helping Hand
    Rank: Major Contributor

    This is basically using a vbscript object:

    # install fonts
    # http://www.mondaiji.com/blog/other/it/10247-windows-install-fonts-via-command-line
    
    $ssfFonts = 0x14
    $fontSourceFolder = ".\fonts"
    $Shell = New-Object -ComObject Shell.Application
    $SystemFontsFolder = $Shell.Namespace($ssfFonts)
    $FontFiles = Get-ChildItem $fontSourceFolder
    $SystemFontsPath = $SystemFontsFolder.Self.Path
    $rebootFlag = $false
    
    foreach($FontFile in $FontFiles) {
        # $FontFile will be copied to this path:
        $targetPath = Join-Path $SystemFontsPath $FontFile.Name
        # So, see if target exists...
        if(Test-Path $targetPath){
            # font file with the same name already there.
            # delete and replace.
            $rebootFlag = $true
            Remove-Item $targetPath -Force
            Copy-Item $FontFile.FullName $targetPath -Force
        }else{
            #install the font.
            $SystemFontsFolder.CopyHere($FontFile.fullname)
        }
    }
    
    #Follow-up message
    if($rebootFlag){
        Write-Host "At least one existing font overwritten. A reboot may be necessary."
    }
    
    if ( -not $? ) { exit 1 }
    
  • #146243

    Participant
    Points: 1,316
    Helping Hand
    Rank: Community Hero

    OK, but what script are you running to have this execute on a remote machine?

    Invoke-Command ?
    PSExec ?

    Either should work. Well, the first one requires that PSRemoting be properly enabled and you have admin privs on each target. The second one even allows you to run in the context of the logged on user.

    You also say, the font folder has many children. You need to use the recurse to get children.

    What errors are you getting, if any at all?

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort