Could you clarify your question a bit? Do you mean:
(1) How do I bring a particular tab to the front so it¡¯s visible?
or
(2) How do I connect to a particular Internet Explorer window when I have
several open?
For (1), there's no easy way to guarantee this; there _are_ possible hacks.
Everyone hates SendKeys because of its poor reliability, but using that (or
possibly some exposed elements of the free AutoItX component) is probably
the most straightforward way. The new IE method Marco mentioned suggests
another possible solution if frame can be determined, since you could
actually renavigate the top frame to a particular site.
For (2), you _can_ do this, but you need to go in another way. What you've
done using the 0x800 flag ( - a clever trick, by the way! ) is open a NEW
Internet Explorer instance using your original IE as a "starter". The
original IE and all new instances are actually equal children of a global
container IE, and you do NOT currently have a direct connection to the other
IE windows. You basically spun them off.
However, you can use the Shell.Application COM object to get all desktop
shell windows, which include all IE windows. With a bit of filtering, you
can get only the IE instances connected to non-file resources into a set
like this:
$ieSet = (New-Object -ComObject Shell.Application).Windows() |
? {$_.LocationUrl -notlike "file:*"} | ? {$_.LocationUrl}
Note that if you DO want to include local files opened in IE, you can drop
the first filter.
The next thing you need to do is select the IE of interest based on the URL.
Here's where you may encounter a problem: there is NO guarantee that the URL
you end up at is identical to the one you chose to navigate to. For example,
when I use
http://support.dell.com.cn
I end up at the URL
http://support.ap.dell.com/support/index.aspx?c=cn&l=zh
However, if you know something certain to be in the particular URL of
interest, you can use it to select the correct URL:
$ieSet | ?{$_.LocationUrl -like "*.dell.*"}
You can also view the titles and URLs pretty quickly for interactive use
like this:
$ieSet | select LocationUrl,LocationName
Another option to consider is to just go ahead and create a new IE for each
window instead. This ensures you know which IE is important, even if it was
redirected. For example, do this:
function New-IE($url)
{
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true;
$ie.Navigate($url);
$ie;
}
$ieTcs = New-IE
http://intra.tcs.com
$ieG = New-IE
http://www.g.com
$ieDell = New-Ie
http://support.dell.com.cn
"MG" <mike99@xxxxxx> wrote in message
news:uDPe#MmFKHA.4280@xxxxxx
> Hi:
> I opened a few tabs in IE8 with PowerShell
>
> $ie = New-Object -ComObject InternetExplorer.Application
> $ie.Visible = $true
> $ie.Navigate("http://intra.tcs.com")
> $ie.Navigate("http://www.g.com",0x0800)
> $ie.Navigate("http://support.dell.com.cn",0x0800)
>
> Can I switch between these tabs using PoS?
>
> Thanks!
>
> MG
>
>