Set the first home page tab while keeping existing tabs in Microsoft IE

Getting started:  Example Script (Zip), Example Script (preview)
Related article(s):  Set the first home page tab while keeping existing tabs in Google Chrome via PowerShell

We often engage in SharePoint or Web App portal projects where the roll out phase may include a requirement to set the default home page tab for the supported browser(s).  While there are many ways to accomplish this for an enterprise, one use case that keeps cropping up at my clients in recent years is as follows:

  1. Set the first tab when the user opens their browser
  2. Set the first tab when the user Hits the home button
  3. Set the (rest of the) user’s existing favorite tabs when they open the browser or hit their home button

The first time I got these requirements I thought:

        1. This is easy to do with group policy or registry
        2. This is easy to do with group policy or registry
        3. Hmm, maybe, let me research and enlist help … fast forward

AHA! That’s not so hard for a one off request after all !

The next two times that #3 came up, I thought:

Ahh CRAP!  I forgot how to do this. 

So here we are writing this down for everyone’s benefit and save future brain damage. 

Because we primarily work in the Windows client space, PowerShell was the chosen tool to accomplish this.  There are many examples out there using scripted methods to address the first two requirements which serve as a great starting point. 

Our example script tackles the requirements above as follows:

Firstly we need to setup the variable for our new URL that will take over the primary tab.  You can see that the example script can take this as a parameter.  While the parameter is not required you can set a default value here as well ( the example is set to this post’s URL by default):

#'http://www.perpetualreality.com/blog/2019/03/29/set-the-first-ho…-in-microsoft-ie/'
#region Establish Script Parameters
    PARAM(
        [Parameter(Position=0, Mandatory=$false)]
        [System.String]
        $global:newRootURL = 'https://wp.me/pawO3b-1x'
    );
#endregion

If you prefer not to use a parameter in your script, that’s fine too.  You can see that (because the new URL is actually required) the example also provides a way to set the static variable too:

if( !($global:newRootURL) -or ($global:newRootURL -eq '')) { $global:newRootURL = 'http://www.perpetualreality.com/blog' };

Great, now that we have the new URL available, we need to tell the script where to put it.  For IE (and used to be Chrome, but not any more) that is a simple registry path:

$regPath = 'HKCU:\Software\Microsoft\Internet Explorer\Main\'

Now, because our detailed requirements dictate that we need to keep the existing tabs a user may have set in their IE options, we need a place to collect those as well.  Here we setup a quick array to handle them:

$global:newSecondariesArr = @();

Here we start by gathering what they have configured as the current first tab:

#Get current root tab URL for IE as string
$primaryTabKeyName = 'start page'
(Get-Itemproperty -Path $regPath -Name $primaryTabKeyName).$primaryTabKeyName | %{ 
    addSecondary $_ $global:newRootURL; 
}

Then collect any others they’ve set:

#Get current secondary tab URLs for IE as string array
$secondaryTabKeyName = 'Secondary Start Pages'
(Get-Itemproperty -Path $regPath -Name $secondaryTabKeyName).$secondaryTabKeyName | %{ 
    addSecondary $_ $global:newRootURL; 
}

You’ll notice in both steps to gather their primary and ancillary tabs above that we call on a function ‘addSecondary’.  While some fancy regex wizardry can accomplish the same in a single line of script, this example function uses some string concatenation to illustrate various string comparisons you may want to take into account. 

Remember, the goal is to validate that the URL being set doesn’t already exist in their tabs and thus won’t get duplicated into the ancillary tabs:

function addSecondary($secVal, $newRootVal){
    if( 
        #Existing string not equal www.perpetualreality.com/
        ($secVal.ToLower() -ne $newRootVal.ToLower()) -and ($secVal.ToLower() -ne ($newRootVal + '/').ToLower()) -and 

        #Existing string not equal http://www.perpetualreality.com or http://www.perpetualreality.com/
        ($secVal.ToLower() -ne ('http://' + $newRootVal).ToLower() ) -and ($secVal.ToLower() -ne ('http://' + $newRootVal + '/').ToLower() ) -and

        #Existing string not equal https://www.perpetualreality.com or https://www.perpetualreality.com/
        ($secVal.ToLower() -ne ('https://' + $newRootVal).ToLower() ) -and ($secVal.ToLower() -ne ('https://' + $newRootVal + '/').ToLower() ) -and

        #Because deep down we are all SharePoint people
        ($secVal.ToLower() -ne ($newRootVal + 'pages/default.aspx').ToLower() )
    ){
        $global:newSecondariesArr += ($secVal);
    }
}

As offered by many bloggers before me, the primary tab is easy for IE and just directly set to registry key:

#Set root tab URL for IE
Set-Itemproperty -Path $regPath -Name $primaryTabKeyName -Value $global:newRootURL

Now that we have collected and compared all the existing tabs, we can add all the URLs to the registry in the right order. With another easy registry key each of the remaining tabs can be set directly to the array:

#Set secondary tab URLs for IE
Set-Itemproperty -Path $regPath -Name $secondaryTabKeyName -Value $global:newSecondariesArr

Tada!

Or … well, wait … We don’t want everyone to have to run this manually right?   Your use case and mileage may vary, but for the use case I outlined above, the recommended best practice for implementation from here was to set this script to run at every login via GPO. We’ve also seen it setup for run once, kiosk, and manual needs.  As stated, our use case may vary.  

Hopefully this blog post has helped to show you how to easily set the first IE homepage tab while keeping your users’ existing tab via a simple script to meet your enterprise use case.  You may also be interested in our post to tackle one way to accomplish this with PowerShell for the Chrome browser too.

Happy scripting everyone!