With the great help of Bronson Magnan I’m continuing to make my application installation scripts used in my Automation Framework evergreen. Evergreen means that no changes are required to the scripts nor the task sequences, the script will always download the latest available version.
I’m pushing all the vendors to provide an evergreen download URL for their products and Parallels have already provided theirs. This is important because when patch Tuesday comes or before because of a critical security fix I can simply just rebuild my Master Images and all sofware will be up to date without lifting a finger. That’s #winops.
The script below will automatically download the latest version of Mozilla Firefox ESTand then run the installation. If there’s no new version and the source already exists it will just skip and jump to installation. Enjoy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
function get-LatestFirefoxESRURL { [cmdletbinding()] [outputtype([String])] param( [ValidateSet("bn-BD","bn-IN","en-CA","en-GB","en-ZA","es-AR","es-CL","es-ES","es-MX")][string]$culture = "en-US", [ValidateSet("win32","win64")][string]$architecture="win64" ) # JSON that provide details on Firefox versions $uriSource = "https://product-details.mozilla.org/1.0/firefox_versions.json" # Read the JSON and convert to a PowerShell object $firefoxVersions = (Invoke-WebRequest -uri $uriSource).Content | ConvertFrom-Json $VersionURL = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$($firefoxVersions.FIREFOX_ESR)/$($architecture)/$($culture)/Firefox%20Setup%20$($firefoxVersions.FIREFOX_ESR).exe" Write-Output $VersionURL } function get-LatestFirefoxESRVersion { [cmdletbinding()] [outputtype([String])] param( [ValidateSet("bn-BD","bn-IN","en-CA","en-GB","en-ZA","es-AR","es-CL","es-ES","es-MX")][string]$culture = "en-US", [ValidateSet("win32","win64")][string]$architecture="win64" ) # JSON that provide details on Firefox versions $uriSource = "https://product-details.mozilla.org/1.0/firefox_versions.json" # Read the JSON and convert to a PowerShell object $firefoxVersions = (Invoke-WebRequest -uri $uriSource).Content | ConvertFrom-Json $Version = [Version]$firefoxVersions.FIREFOX_ESR.replace("esr","") Write-Output $Version } get-LatestFirefoxESRURL get-LatestFirefoxESRVersion # PowerShell Wrapper for MDT, Standalone and Chocolatey Installation - (C)2015 xenappblog.com # Example 1: Start-Process "XenDesktopServerSetup.exe" -ArgumentList $unattendedArgs -Wait -Passthru # Example 2 Powershell: Start-Process powershell.exe -ExecutionPolicy bypass -file $Destination # Example 3 EXE (Always use ' '): # $UnattendedArgs='/qn' # (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode # Example 4 MSI (Always use " "): # $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" # (Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Setting Arguments" -Verbose $StartDTM = (Get-Date) $Vendor = "Mozilla" $Product = "FireFox" $Version = "$(get-LatestFirefoxESRVersion)" $PackageName = "Firefox" $InstallerType = "exe" $Source = "$PackageName" + "." + "$InstallerType" $LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log" $LogApp = "${env:SystemRoot}" + "\Temp\$PackageName.log" $Destination = "${env:ChocoRepository}" + "\$Vendor\$Product\$Version\$packageName.$installerType" $UnattendedArgs = '/SILENT MaintenanceService=false' $url = "$(get-LatestFirefoxESRURL)" $ProgressPreference = 'SilentlyContinue' Start-Transcript $LogPS if( -Not (Test-Path -Path $Version ) ) { New-Item -ItemType directory -Path $Version } CD $Version Write-Verbose "Downloading $Vendor $Product $Version" -Verbose If (!(Test-Path -Path $Source)) { Invoke-WebRequest -Uri $url -OutFile $Source } Else { Write-Verbose "File exists. Skipping Download." -Verbose } Write-Verbose "Starting Installation of $Vendor $Product $Version" -Verbose (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Customization" -Verbose sc.exe config MozillaMaintenance start= disabled Write-Verbose "Stop logging" -Verbose $EndDTM = (Get-Date) Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose Stop-Transcript |
Update 16/09/2018
Fellow MVP Jeremy Moskowitz reached out about getting the script working for Firefox Extended Support Release (ESR) instead of Rapid Release (RR). The script above has been updated to leverage ESR instead of RR because of Firefox Group Policy.
Nice script!
I initially had some trouble with it until I read some of the error messages. This was a newly built system and IE had not been launched for the first time yet. After opening and closing it (and dismissing the first launch wizard), the script ran perfectly.
VERBOSE: Setting Arguments
wget : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet
Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
At C:\Users\xxxx\Desktop\get-newest-firefox.ps1:11 char:22
+ $FFLatestVersion = ((wget -uri $FFReleaseNoticeURL | % content).split …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
+ FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Strange, did not see that on brand new systems, there was an error in the $version which has now been fixed.
Hey. Jeremy M here. I just tested this and it works great. Problem is, most orgs want Firefox ESR, not Firefox RR like that is just downloaded.
Can you please adjust the script or make it a parameter or something to find and download latest ESR version and not just the RR version? Thanks !
This is some additional info from another system that seems to error if IE’s first-launch config is not done yet:
VERBOSE: Setting Arguments
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or
Internet Explorer’s first-launch configuration is not complete.
adding this registry entry prior to launching worked for me 🙂
Windows Registry Editor Version 5.00
;Disable IE11 Welcome Screen
[HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main]
“DisableFirstRunCustomize”=dword:00000001
Is there a way for the installer directory %username%\download\folder to be deleted after running? I’d prefer to keep the directory clean. Or a way to specify where I want the file to download in the script (e.g. C:\Support\Software\Firefox)? Then I can just throw in a delete command to cleanup after it runs?
Sure, you can just set the path. If your run it from C:\Support\Software\Firefox then you’ll get e.g. 60.5 as a sub folder.