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
C:\Users\$username\AppData\Local\Microsoft\Windows\FontsIs 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
$Path=“C:\Source\Font_Post_Grotest”
foreach($File in $FontList) {
if(!($file.name -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
}
}
if($try)
{
$objFolder.CopyHere($File.fullname)
}
}
}