从txt文件打开一堆URL的IE选项卡

时间:2015-09-22 17:02:32

标签: internet-explorer powershell

我正在使用以下powershell打开一堆网址。该脚本只打开第一个URL,然后给出以下错误。知道为什么吗?我使用的是Windows 7和IE 11.

错误:

Method invocation failed because [System.__ComObject] doesn't contain a method named 'Navigate2'.

代码

Function Open-IETabs { 
   param ( 
   [string[]]$Url    )
   begin { 
   $Ie = New-Object -ComObject InternetExplorer.Application    } 
   process {
   $navOpenInBackgroundTab = 0x1000;
   foreach ($Link in $Url) 
   {
    write-host $Link
   $Ie.Navigate2($Link, $navOpenInBackgroundTab) 
   }   
   }    
   end 
   {        
   $Ie.Visible = $true    }
   }
#$path = read-host 'Enter the path of ppm list file'
$path = "c:\texturl.txt"
$url = gc $path


Open-IETabs -Url $Url

1 个答案:

答案 0 :(得分:1)

事实证明代码很好,PowerShell需要以管理员身份打开。