Opening multiple URLs in separate tabs in the same window

I’d like to run a script that opens multiple URLs in their own tabs in the same window in Internet Explorer.

Ok, so, when I run the following script, the URLs come up neatly as three tabs in a single window in Edge.

$urls = @("https://www.merriam-webster.com/","https://www.lexico.com/","https://www.wiktionary.org/")
foreach($url in $urls)
{
Start-Process msedge.exe $url
}

And when I run the script below (the only difference being that the process is now chrome.exe), I get the same neat result in Chrome. Three tabs in the same window.

$urls = @("https://www.merriam-webster.com/","https://www.lexico.com/","https://www.wiktionary.org/")
foreach($url in $urls)
{
Start-Process chrome.exe $url
}

But when I run this script…

$urls = @("https://www.merriam-webster.com/","https://www.lexico.com/","https://www.wiktionary.org/")
foreach($url in $urls)
{
Start-Process iexplore.exe $url
}

… the URLs open up in three separate windows in Internet Explorer.

I know it’s almost a moot point, since Internet Explorer is about to retire, but please indulge me. Is there a way to fix this script so that I can get the same results in Internet Explorer as I do in Edge or Chrome? Or do we just chalk it up to Explorer not being controllable that way?

Searching for “internet explorer open new tab command line” in Google brought up this as the first hit:

1 Like

Well, golly, that sure took me down a rabbit hole for a few hours. But it paid off because I made it work. :face_with_monocle: :nerd_face: Behold…

$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true

$urls = @("www.merriam-webster.com","www.lexico.com","www.wiktionary.org")
$bFirstTab = $true

foreach($url in $urls)
{
    if($bFirstTab)
    {
	$ie.navigate2($url)
	$bFirstTab = $false
    }
    else
    {
	$ie.navigate2($url, 0x0800)
    }
}

Credit where credit is due, and for anyone who is interested, check out this site for further explanation: Powershell Internet Explorer Automation Basics

Also, check out the documentation for ComObjects here: Creating .NET and COM objects - PowerShell | Microsoft Learn

Before today I had no idea what a ComObject was, I had no idea what the navigate2 method was, and I had no idea what a flag was.

The thing that I still find irritating is that I can’t find any documentation on what the flag values actually mean, or the logic from which they are derived. I just had to take for granted that 0x0800 is the value that will make the URL open in a new tab. But, I mean, why? Like, why is the x sitting right there between those two 0s, for example?

Anyway, thank you for steering me in the right direction (even if in a couple of weeks this solution will be purely academic). :+1:

Hey hey … cool. :+1:t4: :clap:t4: :partying_face: And thanks for sharing your solution. :love_you_gesture:t4:

Since creating a good, complete and comprehensive documentation is a lot of work on the one side and no glory in it on the other it’s very often neglegted.

Of course I do not know the meaning of the flag but an “x” at this position of a number means that it is a hex number. So in decimal format it would be 2048. :wink:

1 Like

Oh my goodness, thank you! :astonished: I kept seeing those two numbers in reference to the same method parameter and spent much too long wondering if one was for an older version of Internet Explorer or… or something. :sob: Good to know!

You’re very welcome. I’m glad it helped. :+1:t4:

1 Like