How to Set Default Browser Using PowerShell?

In this tutorial, I will explain how to set the default browser in Windows using PowerShell. As an IT administrator, recently, I got a requirement to set the default browser across multiple machines. PowerShell is the best option to do this.

Note: Make sure you have administrator privileges on the machines you are configuring. Also, the browser(s) you want to set as default installed on the machines.

Default Browser Configuration in Windows

Windows 10 and Windows 11 handle default applications through the Default Apps settings. Changing the default browser manually involves navigating through several menus, but with PowerShell, you can do this easily.

Set Google Chrome as the Default Browser

Let’s start with setting Google Chrome as the default browser. Below is a PowerShell script that accomplishes this task.

Step-by-Step Guide

  1. Open PowerShell as Administrator: Right-click on the Start menu and select “Windows PowerShell (Admin)”.
  2. Run the Script: Copy and paste the following script into the PowerShell window and press Enter.
$chrome = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$assoc = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
$edge = "MSEdgeHTM"
$chromeProgId = "ChromeHTML"

Set-ItemProperty -Path $assoc -Name ProgId -Value $chromeProgId

# Verify the change
Get-ItemProperty -Path $assoc

Explanation:

  • $chrome: Specifies the path to the Chrome executable.
  • $assoc: Specifies the registry path for URL associations.
  • $edge: The ProgId for Microsoft Edge.
  • $chromeProgId: The ProgId for Google Chrome.

This script changes the ProgId for HTTP URL associations to Google Chrome.

I executed the above PowerShell script, and you can see the exact output in the screenshot below:

Set Default Browser Using PowerShell

Read How to Set Proxy in PowerShell?

How to Set Microsoft Edge as the Default Browser

If you prefer Microsoft Edge as the default browser, you can use a similar approach. Below is the PowerShell script for setting Microsoft Edge as the default browser.

Step-by-Step Guide

  1. Open PowerShell as Administrator.
  2. Run the Script:
$edge = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
$assoc = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
$edgeProgId = "MSEdgeHTM"

Set-ItemProperty -Path $assoc -Name ProgId -Value $edgeProgId

# Verify the change
Get-ItemProperty -Path $assoc

Explanation

  • $edge: Specifies the path to the Microsoft Edge executable.
  • $assoc: Specifies the registry path for URL associations.
  • $edgeProgId: The ProgId for Microsoft Edge.

This script sets Microsoft Edge as the default browser by changing the ProgId for HTTP URL associations.

Check out How to Uninstall Microsoft Edge Using PowerShell?

Set Mozilla Firefox as the Default Browser using PowerShell

You can set Mozilla Firefox as the default browser for all users on a Windows machine using a PowerShell script. Here’s the complete script:

# Find the Firefox installation path
$firefoxPath = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe').'(default)'

# Set Firefox as the default browser for HTTP and HTTPS protocols
$httpHandler = "FirefoxURL"
$httpsHandler = "FirefoxURL"
New-ItemProperty -Path "HKCU:\Software\Classes\$httpHandler" -Name "(Default)" -Value "Firefox HTTP Protocol Handler" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\$httpsHandler" -Name "(Default)" -Value "Firefox HTTPS Protocol Handler" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\$httpHandler\DefaultIcon" -Name "(Default)" -Value "$firefoxPath,0" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\$httpsHandler\DefaultIcon" -Name "(Default)" -Value "$firefoxPath,0" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\$httpHandler\shell\open\command" -Name "(Default)" -Value "$firefoxPath -osint -url `"%1`"" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\$httpsHandler\shell\open\command" -Name "(Default)" -Value "$firefoxPath -osint -url `"%1`"" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\FirefoxHTML" -Name "(Default)" -Value "Firefox Document" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\FirefoxHTML\DefaultIcon" -Name "(Default)" -Value "$firefoxPath,1" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\FirefoxHTML\shell\open\command" -Name "(Default)" -Value "$firefoxPath -osint -url `"%1`"" -Force

# Set Firefox as the default application for .htm, .html, .shtml, .xht, .xhtml file extensions
$fileAssociations = @(".htm", ".html", ".shtml", ".xht", ".xhtml")
foreach ($fileAssociation in $fileAssociations) {
    New-ItemProperty -Path "HKCU:\Software\Classes\$fileAssociation" -Name "(Default)" -Value "FirefoxHTML" -Force
}

Here’s what the script does:

  1. It finds the Firefox installation path by querying the registry.
  2. It sets Firefox as the default handler for HTTP and HTTPS protocols by creating the necessary registry keys and values.
  3. It sets Firefox as the default application for .htm, .html, .shtml, .xht, and .xhtml file extensions by creating the necessary registry keys and values.

Check out Uninstall Firefox Using PowerShell

Automate the Process for Multiple Users

If you are managing a network of computers, you might want to apply these changes to all users. You can do this by running the script for each user profile on the machine.

Script for Multiple Users

Here’s a script that iterates over all user profiles and sets the default browser to Google Chrome:

$users = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false }

foreach ($user in $users) {
    $sid = $user.SID
    $assoc = "HKU:\$sid\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
    $chromeProgId = "ChromeHTML"

    Set-ItemProperty -Path $assoc -Name ProgId -Value $chromeProgId
}

# Verify the change for the current user
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"

Explanation

  • $users: Retrieves all user profiles except special ones (like system profiles).
  • $sid: Gets the Security Identifier (SID) for each user.
  • $assoc: Specifies the registry path for URL associations for each user.
  • Set-ItemProperty: Changes the ProgId for each user to Google Chrome.

Read Find Installed Software Using PowerShell

Troubleshooting Common Issues

Now, let me show you some troubleshooting tips for common issues you might encounter.

Issue: “How do you want to open this?”

If you encounter the “How do you want to open this?” prompt even after setting the default browser, it might be due to incomplete registry settings. Ensure all relevant associations (HTTP, HTTPS, .html, .htm) are updated.

Issue: Script Fails with Access Denied

Make sure you are running PowerShell as an Administrator. You might also need to adjust the execution policy to allow running scripts:

Set-ExecutionPolicy RemoteSigned

Issue: Changes Not Reflected Immediately

Sometimes, changes to the registry might not take effect immediately. Restarting the machine or logging off and back on can help.

Conclusion

In this tutorial, I explained how to set up the default browser using PowerShell. I explained how to set Google Chrome and Microsoft Edge as the default browsers in a Windows system.

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.