如何使用PowerShell在现有IE窗口中关闭选项卡



嗨,有人知道如何使用PowerShell在Internet Explorer中打开和关闭选项卡。我可以使用以下

打开一个
 $navOpenInNewTab = 0x800
 # Get running Internet Explorer instances
 $oApp = New-Object -ComObject shell.application
 # Grab the last opened tab
 $oIE = $oApp.Windows() | Select-Object -Last 1
 # Open link in the new tab nearby
 $oIE_Total_Sends = $oIE.navigate($link, $navOpenInNewTab) 
 while ($oIE.busy) {
 sleep -milliseconds 50
 }

如何通过PowerShell关闭此新标签,为什么我不能访问$oIE.Document对象上的getElementByID之类的Internet Explorer方法。

这是一个可以关闭IE的选项卡的函数。

Function Close-IETab {
param($url)
    $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()
        }
    }
}

最新更新