Silently Change Firefox Default Search Engine

Oh, Yahoo! when will you learn you can’t buy friends? Firefox set the default search engine to Yahoo! back in 2014. Since then sys admins have been battling the forced setting. Looking to silently change Firefox default search engine in your network? Can do.

Changing search engines on an individual basis is simple. To make the change on your own home computer read this. If you manage a network of computers, read on.

Silently Change Firefox Default Search Engine

PDQ Deploy Package LibraryPDQ Deploy has a ready-to-deploy, silently installing deployment that will change the Firefox search engine to Google for all your users. In PDQ Deploy, go to the Package Library and import Mozilla Firefox – Set Google as Search Engine. Send this package to any of your target Windows computers that have Mozilla Firefox installed. Upon reboot, your users will have Google set as their browsers. You can choose targets from Active Directory, PDQ Inventory, Spiceworks, etc. How do I use the Package Library?

But let’s break down what’s in the package.

Using PowerShell – Silently Change Firefox Default Search

The package uses the following PowerShell script to make the change. This PowerShell script is provided by the illustrious Kris Powell. (Check out his PowerShell blogs.) This script updates all user profiles on the target computer, if a Firefox profile folder exists for a user. Your users will see the change after they restart their Firefox browser.

Param(
  [string]$SearchProvider="Google"
)

$disclaimer = "By modifying this file, I agree that I am doing so only within Firefox itself, using official, user-driven search engine selection processes, and in a way which does not circumvent user consent. I acknowledge that any attempt to change this file from outside of Firefox is a malicious act, and will be responded to accordingly."
$Pattern    = "{`"\[global\]`"\:{`"current`"\:`"(.*)`",`"hash`"\:`"(.*)`"}}"
$Encoding   = [System.Text.Encoding]::UTF8
$Hasher     = New-Object ([System.Security.Cryptography.SHA256]::Create())

Get-ChildItem -Path "$env:public\..\*\AppData\Roaming\Mozilla\Firefox\Profiles\*" | Where-Object { $_.PSIsContainer } | ForEach-Object {

    $result = [System.Convert]::ToBase64String($Hasher.ComputeHash($Encoding.GetBytes($_.Name + $SearchProvider + $disclaimer)))
    $File   = "$($_.FullName)\search-metadata.json"
    $Data   = "{`"[global]`":{`"current`":`"$SearchProvider`",`"hash`":`"$result`"}}"
    $SearchJsonMozlz4 = "$($_.FullName)\search.json.mozlz4"

    If (-Not (Test-Path $File)) {New-Item -Path $file -ItemType file}

    (Get-Content $File) | Foreach-Object {
        If ($_ | Select-String -Pattern $Pattern) { 
            $_ -replace $Pattern, $Data
        } else {
            $data 
        } 
    } | out-file $File -Encoding utf8
   
   If ((Get-Content $File) -eq $Null) {
        $Data | Out-file $File -Encoding utf8
    }
    If (Test-path $SearchJsonMozlz4) {Remove-Item $SearchJsonMozlz4 -Force}
}

What if I Want Something Other Than Google?

You can use any installed search provider as a value to update. By default in the US-version of Firefox, these values include:

  • Amazon.com
  • Bing
  • DuckDuckGo
  • Google
  • Twitter
  • Wikipedia (en)
  • Yahoo

Put your choice of search engine in place of Google. (Images below show the script in a PowerShell step within PDQ Deploy)

powershell change firefox default
The script (as it currently is written) supports a $SearchProvider parameter with a default value. You can change script every time or just change the parameter when calling the script. Changing both is not required.

firefox search engine powershell

If you used the package from the Package Library, you would simply open up the imported package and edit the parameter field to your desired search engine.

silently change Firefox default search engine

Try PDQ Deploy

Your email address will not be published.

Your Name