lhutton
asked on
Open successive arrays of URLs in IE
I am using this function to open successive arrays of URLs in IE each time the script is run.
- If $site is the first or only URL in the array, and IE is not open, then the URL opens in the first tab. On the next run, the next array is opened if $search = $true.
- If $site is the first or only URL in the array, and IE is open, then the URL opens in a new tab. QUESTION: On the next run, why is the same array opened?
- If $site is not the first or only URL in the array, then the URL opens in a background tab.
function OpenSites($sites) {
$isFirstSite = $true
foreach ($site in $sites) {
if ($isFirstSite -eq $true) {
if ($newInstance) {
$ie.Navigate2($site)
} else {
$ie.Navigate2($site, $navOpenInNewTab)
}
} else {
$ie.Navigate2($site, $navOpenInBackgroundTab)
}
$isFirstSite = $false
}
}
$today = (get-date).DayOfWeek
switch ($today) {
"Someday" {
$search = $false
# Check if Google open
foreach ($tab in $ie) {
if ($tab.LocationURL.Contains("http://www.google.com/"))
{ $search = $true; break }
}
# If Google open on 2nd run, open Yahoo
if ($search) {
OpenSites -sites "http://www.yahoo.com/"
} else {
# 1st run
OpenSites -sites "http://www.google.com/ncr","http://www.bing.com/"
}
}
}
I don't see you changing $newInstance anywhere, meaning it is false all the time?
ASKER
That part of the script:
$newInstance = $false
if (Get-Process iexplore -ea silentlycontinue | Where-Object {$_.MainWindowTitle -ne ""}) {
$ie = (New-Object -COM "Shell.Application").Windows() | ? { $_.Name -eq "Internet Explorer" } | Select-Object -First 1
$newInstance = $false
} else {
$ie = New-Object -COM "InternetExplorer.Application"
$newInstance = $true
$ie.visible = $true
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you: line 46 fixed the issue. Because I am also running the script on Windows 7 (PS2), I am using:
[code]$navOpenInNewTab = 0x800;
$navOpenInBackgroundTab = 0x1000;[/code]
Otherwise, I do not think I have left out anything pertinent.
[code]$navOpenInNewTab = 0x800;
$navOpenInBackgroundTab = 0x1000;[/code]
Otherwise, I do not think I have left out anything pertinent.
You really should consider upgrading to PS 5.1, even on W7 and W2008r2.
ASKER
If you have a moment, I would greatly appreciate your help with this question, please.