How to Get Default Browser Using PowerShell?

If you are a system administrator, you might need to determine the default browser on multiple machines within your network. Using PowerShell, you can easily get a system’s default browser.

In this tutorial, I will explain how to get the default browser using PowerShell.

Note: You should have administrative privileges on the machine(s) you are querying and have PowerShell version 5.1 or higher installed.

Get the Default Browser From Windows Using PowerShell

You can retrieve the default browser using the Windows Registry. Let me show you step-by-step instructions on how to get the default browser from Windows using PowerShell. You can also check out my other article on Set Default Browser Using PowerShell.

Step 1: Open PowerShell with Administrative Privileges

To open PowerShell with administrative privileges:

  1. Press Windows + X and select “Windows PowerShell (Admin)”.
  2. Alternatively, you can search for “PowerShell” in the Start menu, right-click on it, and select “Run as administrator”.

Step 2: Query the Default Browser from the Registry

The default browser settings are stored in the Windows Registry. Specifically, we need to query the HKEY_CURRENT_USER hive where the user-specific settings are stored.

Here’s the PowerShell script to get the default browser:

# Define the registry path
$regPath = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"

# Get the ProgId value which indicates the default browser
$defaultBrowserProgId = (Get-ItemProperty -Path $regPath).ProgId

# Output the default browser ProgId
Write-Output "The default browser ProgId is: $defaultBrowserProgId"

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

Get Default Browser Using PowerShell

Step 3: Interpret the ProgId

The ProgId value returned by the script corresponds to the default browser. Here are some common ProgIds for popular browsers:

  • IE.HTTP for Internet Explorer
  • FirefoxURL for Mozilla Firefox
  • ChromeHTML for Google Chrome
  • MSEdgeHTM for Microsoft Edge

To make the script more user-friendly, we can map these ProgIds to their respective browser names:

# Define a hashtable to map ProgIds to browser names
$browserMapping = @{
    "IE.HTTP" = "Internet Explorer"
    "FirefoxURL" = "Mozilla Firefox"
    "ChromeHTML" = "Google Chrome"
    "MSEdgeHTM" = "Microsoft Edge"
}

# Get the browser name from the ProgId
$defaultBrowser = $browserMapping[$defaultBrowserProgId]

# Output the default browser name
Write-Output "The default browser is: $defaultBrowser"

The complete PowerShell script looks like this:

# Define the registry path
$regPath = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"

# Get the ProgId value which indicates the default browser
$defaultBrowserProgId = (Get-ItemProperty -Path $regPath).ProgId

# Output the default browser ProgId
Write-Output "The default browser ProgId is: $defaultBrowserProgId"
# Define a hashtable to map ProgIds to browser names
$browserMapping = @{
    "IE.HTTP" = "Internet Explorer"
    "FirefoxURL" = "Mozilla Firefox"
    "ChromeHTML" = "Google Chrome"
    "MSEdgeHTM" = "Microsoft Edge"
}

# Get the browser name from the ProgId
$defaultBrowser = $browserMapping[$defaultBrowserProgId]

# Output the default browser name
Write-Output "The default browser is: $defaultBrowser"

I have set my default browser to Google Chrome. So, when I executed the above PowerShell script, it displayed the default browser as shown in the screenshot below:

PowerShell Get Default Browser

Step 4: Handle Unrecognized ProgIds

In some cases, the ProgId might not be in our predefined list. To handle this, we can add a fallback mechanism:

# Check if the ProgId is recognized
if ($browserMapping.ContainsKey($defaultBrowserProgId)) {
    $defaultBrowser = $browserMapping[$defaultBrowserProgId]
} else {
    $defaultBrowser = "Unknown Browser (ProgId: $defaultBrowserProgId)"
}

# Output the default browser name
Write-Output "The default browser is: $defaultBrowser"

Step 5: Running the Script on Multiple Machines

To run this script on multiple machines, you can use PowerShell remoting. Ensure that PowerShell remoting is enabled on the target machines. Here’s an example of how to run the script on a remote machine:

# Define the remote machine name
$remoteMachine = "RemotePC"

# Use Invoke-Command to run the script on the remote machine
Invoke-Command -ComputerName $remoteMachine -ScriptBlock {
    $regPath = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
    $defaultBrowserProgId = (Get-ItemProperty -Path $regPath).ProgId

    $browserMapping = @{
        "IE.HTTP" = "Internet Explorer"
        "FirefoxURL" = "Mozilla Firefox"
        "ChromeHTML" = "Google Chrome"
        "MSEdgeHTM" = "Microsoft Edge"
    }

    if ($browserMapping.ContainsKey($defaultBrowserProgId)) {
        $defaultBrowser = $browserMapping[$defaultBrowserProgId]
    } else {
        $defaultBrowser = "Unknown Browser (ProgId: $defaultBrowserProgId)"
    }

    Write-Output "The default browser on $env:COMPUTERNAME is: $defaultBrowser"
}

Step 6: Exporting the Results

If you need to gather the default browser information from multiple machines and export the results to a file, you can use a loop and export the data to a CSV file:

# Define the list of remote machines
$remoteMachines = @("RemotePC1", "RemotePC2", "RemotePC3")

# Initialize an array to store the results
$results = @()

# Loop through each remote machine
foreach ($machine in $remoteMachines) {
    $result = Invoke-Command -ComputerName $machine -ScriptBlock {
        $regPath = "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
        $defaultBrowserProgId = (Get-ItemProperty -Path $regPath).ProgId

        $browserMapping = @{
            "IE.HTTP" = "Internet Explorer"
            "FirefoxURL" = "Mozilla Firefox"
            "ChromeHTML" = "Google Chrome"
            "MSEdgeHTM" = "Microsoft Edge"
        }

        if ($browserMapping.ContainsKey($defaultBrowserProgId)) {
            $defaultBrowser = $browserMapping[$defaultBrowserProgId]
        } else {
            $defaultBrowser = "Unknown Browser (ProgId: $defaultBrowserProgId)"
        }

        return [PSCustomObject]@{
            ComputerName = $env:COMPUTERNAME
            DefaultBrowser = $defaultBrowser
        }
    }

    $results += $result
}

# Export the results to a CSV file
$results | Export-Csv -Path "DefaultBrowsers.csv" -NoTypeInformation

In this tutorial, I have explained how to get the default browser using PowerShell. You can efficiently get the default browser from multiple machines by querying the Windows Registry, interpreting the ProgId, using PowerShell remoting, and additionally exporting the results to a CSV file.

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.