Skip to content

Instantly share code, notes, and snippets.

@jmadden91
Created November 15, 2022 03:26
Show Gist options
  • Save jmadden91/6e50c4d623c356715ffa7c91a263eb8c to your computer and use it in GitHub Desktop.
Save jmadden91/6e50c4d623c356715ffa7c91a263eb8c to your computer and use it in GitHub Desktop.
# Silent Install Firefox by theSens
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal(
[Security.Principal.WindowsIdentity]::GetCurrent() )
& {
if ($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ))
{
Write-Host "Starting silent firefox installer!" -ForegroundColor Green
$done = $FALSE
# Path for the workdir
$workdir = "c:\firefox-install\"
# Check if work directory exists if not create it
if (Test-Path -Path $workdir -PathType Container)
{
Write-Host "$workdir already exists." -ForegroundColor Yellow
}
else
{
New-Item -Path $workdir -ItemType directory | Out-Null
}
# Find out architecture and donwload corresponding version
if((Get-WmiObject Win32_OperatingSystem).OSArchitecture -ne $null)
{
if((Get-WmiObject Win32_OperatingSystem).OSArchitecture.ToString() -eq "64-bit")
{
$source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US"
Write-Host "64-Bit OS found from WMIObject: Installing Firefox x64"
}
else
{
$source = "https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US"
Write-Host "32-Bit OS found from WMIObject: Installing Firefox x86"
}
}
elseif($ENV:PROCESSOR_ARCHITECTURE -eq "AMD64")
{
$source = "https://download.mozilla.org/?product=firefox-latest&os=win64&lang=en-US"
Write-Host "64-Bit OS found from Powershell process: Installing Firefox x64"
}
else
{
$source = "https://download.mozilla.org/?product=firefox-latest&os=win&lang=en-US"
Write-Host "32-Bit OS found from Powershell process: Installing Firefox x86"
}
# Download
Write-Host "Downloading..."
$downloader = New-Object System.Net.WebClient
$downloader.DownloadFile($source, "$workdir\firefox.exe")
# Start the installation
Start-Process -FilePath "$workdir\firefox.exe" -ArgumentList "/S"
# Wait for the installation to finish
Write-Host "Installing..."
while(-not $done)
{
Start-Sleep -Seconds 5
if(-Not (Get-Process *firefox*))
{$done = $TRUE}
}
# Remove the work files and dir
if($done)
{
Write-Host "Installed!" -ForegroundColor Green
Remove-Item $workdir -Force -Recurse
}
if(-Not (Test-Path -Path $workdir -PathType Container) 2> $null)
{
Write-Host "Working files and directory removed!" -ForegroundColor Green
}
else
{
Write-Host "Working files and directory NOT removed!" -ForegroundColor Red
}
Remove-Variable workdir
Remove-Variable source
Remove-Variable downloader
Remove-Variable done
}
else
{
Write-Host "Please run the silent Firefox installer from an Adminsitrator PowerShell" -ForegroundColor Red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment