Powershell newbie here. In the past I have been able to close 1 of N tabs in MS IE using the follow code.
$url = "https://myhost.com:35001/ibm/console"
#Close Specific IE tab
$oWindows = (New-Object -ComObject Shell.Application).Windows
foreach ($oWindow in $oWindows.Invoke()) {
if ($oWindow.Fullname -match "IEXPLORE.EXE" -and $oWindow.LocationURL -match $url) {
Write-verbose "Closing tab $($oWindow.LocationURL)"
$oWindow.Quit()
}
}
Now I need to do the same with Google’s Chrome. Just changing the “-match” does not seem to work. Some other forums seem to say the -ComObject method is deprecated without providing an example of what should replace it.
$url = "https://myhost.com:35001/ibm/console"
#Close Specific Chrome tab
$oWindows = (New-Object -ComObject Shell.Application).Windows
foreach ($oWindow in $oWindows.Invoke()) {
if ($oWindow.Fullname -match "chrome.exe" -and $oWindow.LocationURL -match $url) {
Write-verbose "Closing tab $($oWindow.LocationURL)"
$oWindow.Quit()
}
}
Question 1) Is there a more up to date method to close in 1 of N tab in MS IE, or Edge?
Question 2) Does the more up to date method work with Chrome too?