Table of Contents
Purpose of the Script
- Automatically download and install the latest version of Foxit Reader.
- Uses Microsoft’s Winget GitHub. repository to locate the official installer.
- Performs a silent installation for all users.
# GitHub API URL for the app manifest.
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/f/Foxit/FoxitReader"
# Fetch version folders then filter only version folders.
$versions = Invoke-RestMethod -Uri $apiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
# Extract and sort version numbers to get the latest version.
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object { [version]$_ } -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
Write-Host "Latest Foxit Reader version: $latestVersion"
# Get contents of the latest version folder to find the .installer.yaml file.
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$installerFile = $latestFiles | Where-Object { $_.name -like "*.installer.yaml" }
# Download and parse YAML content to get the Url of the latest installer file.
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$null = ($yamlContent -join "`n") -match "InstallerUrl:\s+(http.*)"
$installerUrl = $Matches[1]
Write-Host "Downloading installer from: $installerUrl"
# Download the latest installer
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\FoxitReader-latest.exe")
# Start the install or update process.
Start-Process -FilePath "$env:TEMP\FoxitReader-latest.exe" -ArgumentList '/quiet' -Wait
# Cleanup.
Remove-Item -Path "$env:TEMP\FoxitReader-latest.exe" -Force -ErrorAction SilentlyContinue
Write-Host "Foxit Reader installation completed."
Step-by-Step Explanation
Below is a detailed explanation of what each part of the PowerShell script does. The script is designed to automatically install or update Foxit Reader on Windows computers.
1. Define the API URL
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/f/Foxit/FoxitReader"
- Points to the Foxit Reader manifest folder in the winget-pkgs GitHub repository.
- This folder contains subfolders for each version.
2. Get the list of available versions
$versions = Invoke-RestMethod -Uri $apiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
- Fetches all items in the folder (both files and folders).
- Filters to only include directories, because each directory represents a Foxit Reader version.
# Output
PS C:\> $versionFolders
name : 100.0.1
path : manifests/m/Mozilla/Firefox/100.0.1
sha : 9a51e6ecd7a93a90c61ae6324d05c1511bdb8422
size : 0
url : https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/m/Mozilla/Firefox/100.0.1?ref=mast
er
html_url : https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Mozilla/Firefox/100.0.1
git_url : https://api.github.com/repos/microsoft/winget-pkgs/git/trees/9a51e6ecd7a93a90c61ae6324d05c1511bdb8422
download_url :
type : dir
_links : @{self=https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/m/Mozilla/Firefox/100.0.1?r
ef=master; git=https://api.github.com/repos/microsoft/winget-pkgs/git/trees/9a51e6ecd7a93a90c61ae6324d05
c1511bdb8422;
html=https://github.com/microsoft/winget-pkgs/tree/master/manifests/m/Mozilla/Firefox/100.0.1}
...
3. Extract and sort versions
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object {[version]$_} -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
- Extracts folder names (version numbers).
- Sorts them as version objects (not strings) in descending order.
- Picks the latest version (first in the sorted list).
# Output
PS C:\> $sortedVersions
2025.1.0.27937
2024.4.0.27683
2024.3.0.26795
2024.2.3.25184
2024.2.2.25170
2024.2.1.25153
2024.2.0.25138
2024.1.0.23997
2023.3.0.23028
2023.2.0.21408
12.1.3.15356
12.1.2.15332
12.1.1.15289
Inno
4. Get the .installer.yaml file for the latest version
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$installerFile = $latestFiles | Where-Object { $_.name -like "*.installer.yaml" }
- Looks inside the latest version folder.
- Finds the *.installer.yaml file, which contains metadata about the installer (URLs, architecture, etc.).
# Output
PS C:\> $installerFile
name : Foxit.FoxitReader.installer.yaml
path : manifests/f/Foxit/FoxitReader/2025.1.0.27937/Foxit.FoxitReader.installer.yaml
sha : 4ed70802ca451305ee363017cef530baba2b400a
size : 2234
url : https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/f/Foxit/FoxitReader/2025.1.0.27937
/Foxit.FoxitReader.installer.yaml?ref=master
html_url : https://github.com/microsoft/winget-pkgs/blob/master/manifests/f/Foxit/FoxitReader/2025.1.0.27937/Foxit.
FoxitReader.installer.yaml
git_url : https://api.github.com/repos/microsoft/winget-pkgs/git/blobs/4ed70802ca451305ee363017cef530baba2b400a
download_url : https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/f/Foxit/FoxitReader/2025.1.0.27
937/Foxit.FoxitReader.installer.yaml
type : file
_links : @{self=https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/f/Foxit/FoxitReader/2025.1.
0.27937/Foxit.FoxitReader.installer.yaml?ref=master; git=https://api.github.com/repos/microsoft/winget-p
kgs/git/blobs/4ed70802ca451305ee363017cef530baba2b400a; html=https://github.com/microsoft/winget-pkgs/bl
ob/master/manifests/f/Foxit/FoxitReader/2025.1.0.27937/Foxit.FoxitReader.installer.yaml}
5. Extract installer URLs from YAML to find the URL of the latest version
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$yamlString = $yamlContent -join "`n"
$installerUrls = [regex]::Matches($yamlString, "InstallerUrl:\s+(http[^\s]+)") | ForEach-Object { $_.Groups[1].Value }
$installerUrl = $installerUrls[1]
- Downloads the YAML file as raw text.
- Extracts all InstallerUrl entries using regular expressions.
- Picks the URL using an index number.
# Output
PS C:\> $installerUrl
https://cdn01.foxitsoftware.com/product/reader/desktop/win/2025.1.0/FoxitPDFReader20251_L10N_Setup.exe
6. Download the installer
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\FoxitReader-latest.exe")
- Downloads the installer to the Windows temp folder ($Env:Temp)
7. Install Foxit Reader silently
Start-Process -FilePath "$env:TEMP\FoxitReader-latest.exe" -ArgumentList '/quiet' -Wait
- Runs the installer in silent mode, no user interaction.
8. Clean up the installer and notify to user
Remove-Item -Path "$env:TEMP\FoxitReader-latest.exe" -Force -ErrorAction SilentlyContinue
Write-Host "Foxit Reader installation completed."
- Deletes the installer after installation to keep the system clean.
- Outputs a message to confirm the installation status.
How to install using PowerShell
To install the app, simply open PowerShell as an administrator, copy the code snippets below, paste them into the PowerShell window, and press .
# GitHub API URL for the app manifest.
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/f/Foxit/FoxitReader"
# Fetch version folders then filter only version folders.
$versions = Invoke-RestMethod -Uri $apiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$versionFolders = $versions | Where-Object { $_.type -eq "dir" }
# Extract and sort version numbers to get the latest version.
$sortedVersions = $versionFolders | ForEach-Object { $_.name } | Sort-Object { [version]$_ } -Descending -ErrorAction SilentlyContinue
$latestVersion = $sortedVersions[0]
Write-Host "Latest Foxit Reader version: $latestVersion"
# Get contents of the latest version folder to find the .installer.yaml file.
$latestApiUrl = "$apiUrl/$latestVersion"
$latestFiles = Invoke-RestMethod -Uri $latestApiUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$installerFile = $latestFiles | Where-Object { $_.name -like "*.installer.yaml" }
# Download and parse YAML content to get the Url of the latest installer file.
$yamlUrl = $installerFile.download_url
$yamlContent = Invoke-RestMethod -Uri $yamlUrl -Headers @{ 'User-Agent' = 'PowerShell' }
$null = ($yamlContent -join "`n") -match "InstallerUrl:\s+(http.*)"
$installerUrl = $Matches[1]
Write-Host "Downloading installer from: $installerUrl"
# Download the latest installer
$webClient = [System.Net.WebClient]::new()
$webClient.DownloadFile($installerUrl, "$env:TEMP\FoxitReader-latest.exe")
# Start the install or update process.
Start-Process -FilePath "$env:TEMP\FoxitReader-latest.exe" -ArgumentList '/quiet' -Wait
# Cleanup.
Remove-Item -Path "$env:TEMP\FoxitReader-latest.exe" -Force -ErrorAction SilentlyContinue
Write-Host "Foxit Reader installation completed."
Installing using a PowerShell script
Alternatively, you can create a PowerShell script using the code snippet above. For instance, I’ve created and save a script at “C:\Scripts\install.ps1″.
Next, open PowerShell (or Terminal) as an administrator and execute the PowerShell script using either the call operator or dot notation.
& "C:\Scripts\install.ps1"
# Output
PS C:\> & "C:\Scripts\install.ps1"
Latest Foxit Reader version: 2025.1.0.27937
Downloading installer from: https://cdn01.foxitsoftware.com/product/reader/desktop/win/2025.1.0/FoxitPDFReader20251_L10N_Setup.exe
Now installing, please wait...
Setup finished.
Foxit Reader installation completed.
PowerShell execution policy
Root cause: The Windows PowerShell execution policy is designed to block untrusted scripts from impacting your Windows client environment. These policies act as security settings that define the trust level for scripts executed in PowerShell. On client operating systems, the default execution policy is set to Restricted, which stops Windows PowerShell commands and scripts from running.
To fix the issue, adjust the execution policy by running the following command:
Set-ExecutionPolicy RemoteSigned
You’ll encounter a security risk warning. Enter “A” when prompted to continue.
PS C:\> Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy
might expose you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): A
PS C:\>
PS C:\> Get-ExecutionPolicy
RemoteSigned
Use Cases
- Automated software deployment
- Scheduled automatic updates
- Silent install for non-technical users
- Alternative to winget or manual downloads