mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-11 11:04:46 +02:00
Added parameter for source folder with fallback prompt if not provided
This commit is contained in:
parent
13244e37fe
commit
068c711b94
@ -1,7 +1,7 @@
|
|||||||
The *install-fonts.ps1* Script
|
The *install-fonts.ps1* Script
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
install-fonts.ps1
|
install-fonts.ps1 [[-sourceFolder] <string>]
|
||||||
|
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -17,25 +17,38 @@ Parameters
|
|||||||
Script Content
|
Script Content
|
||||||
--------------
|
--------------
|
||||||
```powershell
|
```powershell
|
||||||
$sourceFolder = "D:\related\FONT"
|
param(
|
||||||
|
[string]$sourceFolder = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
# If no parameter is given, prompt the user for the source folder
|
||||||
|
if (-not $sourceFolder) {
|
||||||
|
$sourceFolder = Read-Host "Please enter the path to the source folder"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set the destination folder for fonts, you don't need to change this
|
||||||
$fontsFolder = "$env:SystemRoot\Fonts"
|
$fontsFolder = "$env:SystemRoot\Fonts"
|
||||||
|
|
||||||
|
# Get all font files from the source folder
|
||||||
$fontFiles = Get-ChildItem -Path $sourceFolder -Filter *.ttf
|
$fontFiles = Get-ChildItem -Path $sourceFolder -Filter *.ttf
|
||||||
|
|
||||||
foreach ($font in $fontFiles) {
|
foreach ($font in $fontFiles) {
|
||||||
|
# Copy font files to the Fonts folder
|
||||||
$destination = "$fontsFolder\$($font.Name)"
|
$destination = "$fontsFolder\$($font.Name)"
|
||||||
Copy-Item -Path $font.FullName -Destination $destination -Force
|
Copy-Item -Path $font.FullName -Destination $destination -Force
|
||||||
|
|
||||||
|
# Add font to registry
|
||||||
$fontName = [System.IO.Path]::GetFileNameWithoutExtension($font.Name)
|
$fontName = [System.IO.Path]::GetFileNameWithoutExtension($font.Name)
|
||||||
$fontRegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
|
$fontRegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
|
||||||
|
|
||||||
|
# For TrueType fonts
|
||||||
$fontType = "TrueType"
|
$fontType = "TrueType"
|
||||||
|
|
||||||
|
# Add the registry entry
|
||||||
New-ItemProperty -Path $fontRegistryPath -Name "$fontName ($fontType)" -PropertyType String -Value $font.Name -Force
|
New-ItemProperty -Path $fontRegistryPath -Name "$fontName ($fontType)" -PropertyType String -Value $font.Name -Force
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Output "Fonts have been installed successfully."
|
Write-Output "Fonts have been installed successfully."
|
||||||
```
|
```
|
||||||
|
|
||||||
*(page generated by convert-ps2md.ps1 as of 01/29/2025 19:36:33)*
|
*(page generated by convert-ps2md.ps1 as of 01/29/2025 20:04:23)*
|
@ -1,5 +1,11 @@
|
|||||||
# Set the source folder containing the fonts, Like the example below
|
param(
|
||||||
$sourceFolder = "D:\related\FONT"
|
[string]$sourceFolder = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
# If no parameter is given, prompt the user for the source folder
|
||||||
|
if (-not $sourceFolder) {
|
||||||
|
$sourceFolder = Read-Host "Please enter the path to the source folder"
|
||||||
|
}
|
||||||
|
|
||||||
# Set the destination folder for fonts, you don't need to change this
|
# Set the destination folder for fonts, you don't need to change this
|
||||||
$fontsFolder = "$env:SystemRoot\Fonts"
|
$fontsFolder = "$env:SystemRoot\Fonts"
|
||||||
|
Loading…
Reference in New Issue
Block a user