I have created a function that opens an array of one or more URLs in IE: the first URL should be opened in the first tab; successive URLs should be opened in background tabs. If IE is already open, the first URL should be opened in a new tab to preserve existing URLs.
function OpenSites($sites) {
$isFirstSite = $true
foreach ($site in $sites) {
if ($isFirstSite) {
if (Get-Process iexplore -ea silentlycontinue | Where-Object {$_.MainWindowTitle -ne ""}) {
$ie.Navigate2($site, $navOpenInNewTab)
} else { $ie.Navigate2($site) }
$isFirstSite = $false
} else { $ie.Navigate2($site, $navOpenInBackgroundTab) }
}
}