powershell - PowerExplorer.Application com对象和Windows 2012 in Powershell

标签 powershell com internet-explorer-10 createobject

我正在尝试使用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/

    相关文章:

    python - 在一个位置为多个站点更新 azure token ,无需域访问

    c++ - 与普通 DLL 相比,使用 COM 有什么优势?

    powershell - 如何使用 PowerShell 访问第三方 OLE DLL 的方法和属性?

    css - Flexbox IE 对齐 self

    vuejs2 - Vuejs Internet Explorer 兼容性问题(版本 10 和 11)

    html - IE10 直接写入 'Empty Text Node' 吗?

    PowerShell v5 - 如何将模块安装到没有互联网连接的计算机上?

    windows - 在 Powershell 脚本中复制命令的目的是什么?

    powershell - 格式化嵌套的哈希表

    c# - 哪一个是错误的? Msdn 或头文件