我正在尝试使用Windows 2012访问Internet Explorer com对象的文档。该代码在Windows 2008中效果很好,但是当我尝试在Windows 2012上运行它(全新安装,在多个服务器上尝试过)时,代码相同代码停止工作。换句话说,$ ie.document.documentHtml返回为null。
下面是代码:
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate2("http://www.example.com/")
while($ie.busy) {start-sleep 1}
$ie.document.documentHtml.innerhtml
Windows 2012中的interexplorer com对象是否已更改?如果是,如何在Windows 2012中检索文档内容?
提前致谢
编辑:增加了赏金使事情变得甜蜜起来。 Invoke-WebRequest很不错,但它仅在Windows 2012上有效,但我需要使用Internet Explorer,并且必须在Windows 2008和Windows 2012上均可使用。这也不是一个选择。
edit2:由于我需要在多个Windows服务器(包括2008和2012)上远程调用脚本,因此我不希望手动复制文件
最佳答案
这是一个已知的错误:http://connect.microsoft.com/PowerShell/feedback/details/764756/powershell-v3-internetexplorer-application-issue
解决方法的摘录:
因此,这是一种解决方法:
Microsoft.html.dll
(例如:从C:\ Program Files(x86)\ Microsoft.NET \ Primary Interop程序集复制到脚本的位置(可以是网络驱动器)Load-Assembly.ps1
脚本(下面和下面提供的代码:http://sdrv.ms/U6j7Wn)将程序集类型加载到内存中例如:。\ Load-Assembly.ps1 -Path。\ microsoft.mshtml.dll
然后像往常一样继续创建IE对象等。警告:在处理write()和writeln()方法时,请使用向后兼容的方法:IHTMLDocument2_write()和IHTMLDocument2_writeln()。
关于powershell - PowerExplorer.Application com对象和Windows 2012 in Powershell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21197141/