【发布时间】:2019-04-29 21:52:57
【问题描述】:
我有这段 PowerShell 脚本:
$IE = New-Object -com InternetExplorer.Application
$IE.Navigate($URL)
While ($IE.ReadyState -Ne 4) {Start-Sleep -Milliseconds 100}
$IE.Document.ParentWindow.ExecScript("var JSIEVariable = new XMLSerializer().serializeToString(document);", "javascript")
$Obj = $IE.Document.ParentWindow.GetType().InvokeMember("JSIEVariable", 4096,
$Null, $IE.Document.parentWindow, $Null)
$HTML = $Obj.ToString()
$IE.Quit()
在 Windows 10 上它工作正常,但在 Windows Server 2016 上的第 4、5 和 6 行我收到错误:
您不能在空值表达式上调用方法。
我很确定这与 Windows Server 中防止 IE 运行 Javascript 的额外安全性有关。必须有某种方法来回拨安全性,使其与 Windows 10 更加相提并论,以便该脚本可以正常运行,但我不知道如何。我已关闭 IE 增强安全配置并确保启用了活动脚本。除此之外,我不知道还能做什么。
【问题讨论】:
标签: javascript powershell internet-explorer windows-server windows-server-2016