Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open tab in existing IE instance

$ie = New-Object -com internetexplorer.application

Everytime i open a new website with this object(ie every time when script runs) it is opened in a new IE window and i don't want it to do that. I want it to be opened in a new tab but that too in a previously opened IE window. I want to reuse this object when the script runs next time. I don't want to create a new object

So is there any way like to check for the instances of internet explorer and to reuse its instance ???

I tried this as a solution:

First you have to attach to the already running Internet Explorer instance:

$ie = (New-Object -COM "Shell.Application").Windows() `
    | ? { $_.Name -eq "Windows Internet Explorer" }

Then you Navigate to the new URL. Where that URL is opened is controlled via the Flags parameter:

$ie.Navigate("http://www.google.com/", 2048)

but am not able to call navigate method on this newly created object $ie.

like image 668
Rohit2194017 Avatar asked Mar 21 '13 10:03

Rohit2194017


3 Answers

You can use Start-Process to open the URL. If a browser window is already open, it will open as a tab.

Start-Process 'http://www.microsoft.com'
like image 95
aphoria Avatar answered Nov 16 '22 00:11

aphoria


First you have to attach to the already running Internet Explorer instance:

$ie = (New-Object -ComObject "Shell.Application").Windows() |
      Where-Object { $_.Name -eq "Windows Internet Explorer" }

Then you Navigate to the new URL. Where that URL is opened is controlled via the Flags parameter:

$ie.Navigate("http://www.google.com/", 2048)

Edit: In case 2 or more IE instances are running (additional tabs count as additional instances as well) the enumeration will return an array, so you have to select a particular instance from the array:

$ie[0].Navigate("http://www.google.com/", 2048)
like image 23
Ansgar Wiechers Avatar answered Nov 15 '22 23:11

Ansgar Wiechers


You can use this if Internet Explorer is not your default browser:

Function Open-IETabs {
    param (
        [string[]]$Url
    )
    begin {
        $Ie = New-Object -ComObject InternetExplorer.Application
    }
    process {
        foreach ($Link in $Url) {
            $Ie.Navigate2($Link, 0x1000)
        }
    }
    end {
        $Ie.Visible = $true
    } 
}

I found this on PowerShell.com

like image 27
PowerShellGirl Avatar answered Nov 16 '22 00:11

PowerShellGirl