# Update-Firefox
# ----------------------------------------------------------------------------
# This Script installs the current Firefox version
#
# Returns: -
# ----------------------------------------------------------------------------
# Copyright (c) 2024 by Digital Data GmbH
#
# Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
# Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
# ----------------------------------------------------------------------------
# Creation Date / Author: 04.11.2024 / MK
# Version Date / Editor: 04.11.2024 / MK
# Version Number: 1.0.0.0
#Requires –Version 4.0
Clear-Host
Function Get-CurrentFirefoxVersion {
$CurrentFirefoxVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -Name "(default)" -ErrorAction SilentlyContinue)."(default)"
Write-Host "Current Firefox Version: $CurrentFirefoxVersion"
Return $CurrentFirefoxVersion
} #end function
Function Get-NewFirefoxVersion {
# Fetch the content of the Firefox release notes page
$response = Invoke-WebRequest -Uri "https://www.mozilla.org/de/firefox/notes/"
$pageContent = $response.Content
# Extract the version number using a regular expression
if ($pageContent -match '
Firefox\s+([0-9]+\.[0-9]+),\s+See\s+All\s+New\s+Features,\s+Updates\s+and\s+Fixes<\/title>') {
$NewFirefoxVersion = $matches[1]
Write-Host "Latest Firefox Version: $latestVersion"
Return $NewFirefoxVersion
} else {
Write-Host "Could not find the Firefox version number on the release notes page."
Return $NULL
}
} #end function
Function Update-NewFirefoxVersion {
Param ($NewFirefoxVersion)
# Define the URL for the latest Firefox installer
$NewFirefoxVersionURL = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$NewFirefoxVersion/win64/de/Firefox%20Setup%20$NewFirefoxVersion.msi"
# Use Invoke-WebRequest to download the installer
Write-Host "Downloading Firefox Version $NewFirefoxVersion..."
Invoke-WebRequest -Uri $NewFirefoxVersionURL -OutFile "$env:TEMP\Firefox$NewFirefoxVersion.msi"
Try {
$FirefoxProcess = Get-Process -Name "firefox" -ErrorAction SilentlyContinue
If ($FirefoxProcess) {Stop-Process -Name "firefox" -Force -ErrorAction Stop}
Write-Host "Installing Firefox Version $NewFirefoxVersion, please wait..."
$ArgumentList = "/i $env:TEMP\Firefox$NewFirefoxVersion.msi INSTALL_DIRECTORY_PATH=""D:\ProgramFiles\Mozilla Firefox"" /quiet"
Start-Process -FilePath "msiexec.exe" -ArgumentList $ArgumentList -Wait
} Catch {
Write-Host "ERROR!"
Write-Host $Error[0].ToString()
} Finally {
Write-Host "Cleaning Up!"
Remove-Item "$env:TEMP\Firefox$NewFirefoxVersion.msi" -Force
} #end try/catch/finally
} #end function
$CurrentFirefoxVersion = Get-CurrentFirefoxVersion
$NewFirefoxVersion = Get-NewFirefoxVersion
If ($NewFirefoxVersion -gt $CurrentFirefoxVersion) {
Write-Host "Install or Update is neccessary!"
Update-NewFirefoxVersion -NewFirefoxVersion $NewFirefoxVersion
Write-Host "Install or Update is completed!"
} Else {
Write-Host "No Install or Update is neccessary!"
} #end if/else