How Do You Install Firefox on a Windows Server with PowerShell?

Problem scenario
You want to install Firefox on a Windows server without using the traditional GUI method. What should you do?

Solution
Updated on 5/16/21
1. Open PowerShell ISE as Administrator (right click it, go to More -> Run as Administrator).
2. Run this script (e.g., firefox.ps1):

# This script was mostly taken from https://forum.pulseway.com/topic/1940-install-firefox-with-powershell/

# www.continualintegration.com changed the version number of Firefox and added some comments
# Silent Install Firefox 

# Download URL: https://www.mozilla.org/en-US/firefox/all/

# Path for the workdir
$workdir = "c:\installer\"

# Check if work directory exists if not create it

If (Test-Path -Path $workdir -PathType Container)
{ Write-Host "$workdir already exists" -ForegroundColor Red}
ELSE
{ New-Item -Path $workdir  -ItemType directory }

# Download the installer

$source = "https://download.mozilla.org/?product=firefox-88.0.1-SSL&os=win64&lang=en-US"
$destination = "$workdir\firefox.exe"

# Check if Invoke-Webrequest exists otherwise execute WebClient

if (Get-Command 'Invoke-Webrequest')
{
     Invoke-WebRequest $source -OutFile $destination
}
else
{
    $WebClient = New-Object System.Net.WebClient
    $webclient.DownloadFile($source, $destination)
}

# Start the installation

Start-Process -FilePath "$workdir\firefox.exe" -ArgumentList "/S"

# Wait XX Seconds for the installation to finish

Start-Sleep -s 35

# Remove the installer

rm -Force $workdir\firefox*

# write-host should be changed to write-verbose  # we have not tried it yet with these directions
# https://devblogs.microsoft.com/scripting/understanding-streams-redirection-and-write-host-in-powershell/

Leave a comment

Your email address will not be published. Required fields are marked *