I would like help with the following ps script that I took from reddit to install fonts for all Windows 11 users, below is the original script:
#set font source location$FontFolder = "FONT LOCATION"$FontItem = Get-Item -Path $FontFolder#go through all folders in source and list all fon, otf, ttc and ttf files$FontList = Get-ChildItem -Path $PSScriptRoot -Include ('*.fon','*.otf','*.ttc','*.ttf') -Recurseforeach ($Font in $FontList) {Write-Host 'Installing font -' $Font.BaseNameCopy-Item $Font "C:\Windows\Fonts"#register font for all usersNew-ItemProperty -Name $Font.BaseName -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $Font.name}
In the original script I need to set the full path of the folder where the fonts are, and if I copy this folder to another drive I have to update the path before running it, but what I need and want is for it to recognize the folder where it is being executed without me having to set the path, as happens with a batch script that starts with the command cd /d "%~dp0", like the one below that I use to install the Notepad++:
mode con lines=30 cols=70@ECHO offcd /d "%~dp0"cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "cmd.exe", "/k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B )clsecho.@echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßß@echo ßß S O F T E H A R D S O L U T I O N S ßß@echo ßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßßßß@echo ßßßß@echo ßß I N F O R M A T I C A ßß@echo ßßßß@echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß@CHCP 1252 >NUL @Title Silent installation of Notepad++ software version 64-bit.. echo. echo. We are starting the silent installation of the software echo. echo. "Notepad++ 64-bit" echo. echo. When the installation is complete echo. this message will disappear and the application echo. will start so you can configure it before using it. echo. @echo OFFFOR %%i IN ("npp*.exe") DO Set FileName="%%i"%FileName% /Secho. Installation completed successfully - Starting Notepad Plus Plus 64-bit!@Start explorer.exe "%ProgramData%\Microsoft\Windows\Start Menu\Programs\Notepad++.lnk"timeout /t 4exit
I search for the equivalent "cd /d "%~dp0"" command and I just found this "$PSScriptRoot", did anyone knows if this will solve my problem?
Thanks in advance for any help.
Best Regards