The function Install-Font
lets you install fonts using PowerShell. It triggers the Install for all users command, utilizing a technique demonstrated by Stefan Kanthak:
function Install-Font {
param(
[Parameter( Mandatory, ValueFromPipeline )]
[System.IO.FileInfo[]]
$FontFile,
[switch]
$WhatIf
)
begin {
$shell = New-Object -ComObject 'Shell.Application';
}
process {
foreach( $file in $FontFile ) {
if( $WhatIf ) {
Write-Host -Message(
'Installing font "{0}".' -f $file.Name
);
} else {
$shell.NameSpace(
$file.Directory.FullName
).ParseName(
$file.Name
).Verbs() | ForEach-Object {
if( $_.Name -eq 'Install for &all users' ) {
$_.DoIt();
}
};
}
}
}
}
Install-Font.ps1Use this function as follows:
PS C:\> Get-ChildItem -LiteralPath "$env:USERPROFILE\Downloads" -File -Filter *.ttf | Install-Font