How to Uninstall Firefox Using PowerShell?

As an IT administrator, I recently got a requirement to remove the Firefox browser from multiple endpoints efficiently. In this tutorial, I explain how to uninstall Mozilla Firefox using PowerShell.

Note: You need administrative privileges on the target machines to uninstall Firefox using PowerShell.

Uninstall Firefox Using PowerShell (Step By Step)

Now, follow the step-by-step guide to uninstall Firefox using PowerShell.

Step 1: Open PowerShell with Administrative Privileges

First, you need to run PowerShell as an administrator. To do this:

  1. Click on the Start menu.
  2. Type PowerShell.
  3. Right-click on Windows PowerShell and select Run as administrator.

Step 2: Identify the Installed Firefox Version

Before uninstalling Firefox, it’s crucial to identify the installed version. This helps ensure that you are targeting the correct application. You can use the following command to list all installed programs:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version

Look for entries related to Mozilla Firefox in the output.

Check out Get and Set Window Size in PowerShell

Step 3: Uninstall Firefox Using PowerShell

To uninstall Firefox, you can use the Start-Process cmdlet to execute the uninstaller. Firefox’s uninstaller is typically located in the installation directory. Here’s a generic script to uninstall Firefox:

$firefoxPath = "C:\Program Files\Mozilla Firefox\uninstall\helper.exe"
if (Test-Path $firefoxPath) {
    Start-Process -FilePath $firefoxPath -ArgumentList "/S" -Wait
    Write-Output "Firefox has been successfully uninstalled."
} else {
    Write-Output "Firefox uninstaller not found."
}

Step 4: Uninstall Firefox from Multiple Machines

If you need to uninstall Firefox from multiple computers, you can use PowerShell Remoting. Ensure that PowerShell Remoting is enabled on all target machines. Here’s a script to uninstall Firefox from multiple computers:

$computers = @("PC1", "PC2", "PC3") # Replace with your computer names
$scriptBlock = {
    $firefoxPath = "C:\Program Files\Mozilla Firefox\uninstall\helper.exe"
    if (Test-Path $firefoxPath) {
        Start-Process -FilePath $firefoxPath -ArgumentList "/S" -Wait
        Write-Output "Firefox has been successfully uninstalled on $env:COMPUTERNAME."
    } else {
        Write-Output "Firefox uninstaller not found on $env:COMPUTERNAME."
    }
}

foreach ($computer in $computers) {
    Invoke-Command -ComputerName $computer -ScriptBlock $scriptBlock
}

Check out Get Window Titles Using PowerShell

Step 5: Handling User Profiles

Sometimes, Firefox installations are user-specific, residing in the %appdata% directory. To handle such cases, you can adapt the script to uninstall Firefox from user profiles:

$users = Get-WmiObject -Class Win32_UserProfile | Where-Object { $_.Special -eq $false }
foreach ($user in $users) {
    $firefoxPath = "$($user.LocalPath)\AppData\Local\Mozilla Firefox\uninstall\helper.exe"
    if (Test-Path $firefoxPath) {
        Start-Process -FilePath $firefoxPath -ArgumentList "/S" -Wait
        Write-Output "Firefox has been successfully uninstalled from $($user.LocalPath)."
    } else {
        Write-Output "Firefox uninstaller not found in $($user.LocalPath)."
    }
}

Step 6: Verify Uninstallation

After running the script, it’s good practice to verify that Firefox has been uninstalled. You can do this by checking the installed programs again:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name, Version | Where-Object { $_.Name -match "Mozilla Firefox" }

If Firefox is no longer listed, the uninstallation was successful.

Read Get Windows Services Using PowerShell

Uninstall Firefox Using PowerShell

Errors and Troubleshooting Steps

While uninstalling Firefox using Microsoft PowerShell, you might find some errors. Here are a few errors and how to fix these errors.

Issue 1: Uninstaller Not Found

If the script cannot find the uninstaller, ensure that the path to helper.exe is correct. Firefox may be installed in a different directory, especially if custom paths were used during installation.

Issue 2: Insufficient Privileges

Ensure you are running PowerShell with administrative privileges. Without these, the script will not have the necessary permissions to uninstall software.

Issue 3: Remote Execution Errors

If you’re using PowerShell Remoting and encounter errors, check that PowerShell Remoting is enabled on all target machines and that you have the necessary permissions to execute scripts remotely.

Conclusion

In this tutorial, I explained how to uninstall Firefox using PowerShell. I have also shown how to uninstall Firefox from multiple machines using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.