Installing Font using Admin Account to install for Local Users

Hi, I have created a script from connecting scripts together and adapting them. I use 1 script to install Fonts this works well when running on the local computer but I would like to run in through a Device Manager that manages all my computers. However when the script runs its running as admin.

I think its because in a bit of my script is has

Is there any PowerShell script that will generate a list of users and replace $username with that so that when this script runs it will do it for all the users on that computer?


Full Script Below

$FONTS = 0x14
$FontItem = Get-Item -Path $Path
$FontList = Get-ChildItem -Path “$FontItem*” -Include (’.fon’,’.otf’,’.ttc’,’.ttf’)
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($FONTS)
$Fontdir = dir $Path
$username = $env:UserName

foreach($File in $FontList) {
if(!($ -match “pfb$”))
$try = $true
$installedFonts = @(Get-ChildItem C:\Users$username\AppData\Local\Microsoft\Windows\Fonts | Where-Object {$_.PSIsContainer -eq $false} | Select-Object basename)
$name = $File.baseName

foreach($font in $installedFonts)
$font = $font -replace “", “”
$name = $name -replace "
”, “”
if($font -match $name)
$try = $false

Get-Childitem will take wildcards in the path parameter. See Get-Help Get-ChildItem:

    -Path <System.String[]>
        Specifies a path to one or more locations. Wildcards are accepted. The default location is the current directory ('.').

        Required?                    false
        Position?                    0
        Default value                Current directory
        Accept pipeline input?       True (ByPropertyName, ByValue)
        Accept wildcard characters?  true

With that you can just do this:

Get-ChildItem -Path C:\Users\*\AppData\Local\Microsoft\Windows\Fonts -File

Also if you have version PS version 5.1 you can just use the -File switch parameter to only return files. That will save you the pipe overhead to Where-Object.