【问题标题】:Invoke-WebRequest Error调用 WebRequest 错误
【发布时间】:2018-03-22 09:16:42
【问题描述】:

最近晋升为系统管理员,我真的刚刚开始设置。我们有一个用于检查某些服务的 powershell 脚本。似乎适用于所有其他管理员。我认为这是权限,但想在这里查看我是否遗漏了什么。

Powershell 脚本

Import-Module WebAdministration -ErrorAction SilentlyContinue 


#Change the location to match your file.
$ServerLocation = "C:\Scripts\Servers"
$StartTime = Get-Date


$ServerName = Get-Content "$ServerLocation\ServerText.txt"


ForEach ($Server in $ServerName)
{
   #$Server = "ServerPD20" 
   #Invoke-WebRequest -Uri http://$Server/ServerService/ServerCalculator.svc | Select StatusDescription
   Write-Host $Server -ForegroundColor Cyan
   $Check = Invoke-WebRequest -Uri http://$Server/ServerService/ServerCalculator.svc
   If($Check.StatusDescription -eq 'OK')
   {
      Write-Host "Server Calculator Service is:" $Check.StatusDescription
      Write-Host "Status Code:" $Check.StatusCode
      $Time = (Measure-Command {Invoke-WebRequest -Uri http://$Server/ServerService/ServerCalculator.svc}).TotalSeconds
      Write-Host "Total Request Time: $Time seconds" `n -ForegroundColor Gray
   }
   ElseIf($Check.StatusDescription -ne 'OK')
   {
      Write-Host "Server Calculator Service is NOT ONLINE" -ForegroundColor Red
      Write-Host "Status Code:" $Check.StatusCode `n
   }
}
$RunTime = Get-Date
Write-Host `n"Start Time" $StartTime
Write-Host "Run Time: "$RunTime -ForegroundColor Yellow

我得到的输出

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or  Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.  At C:\Scripts\Folder\CalculatorCheck.ps1:17 char:13
+    $Check = Invoke-WebRequest -Uri http://$Server/ServerCalculator ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
    + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

有两点需要注意。

我已经使用运行 powershell 脚本的同一帐户登录了所有四个框。我右键单击并以其他用户身份运行。我输入的用户名是我登录所有 4 个服务器并确保 IE 已打开的用户名。

如果我在“$Check = Invoke-WebRequest -Uri http://$Server/ServerService/ServerCalculator.svc”之后添加 -UseBasicParsing,我就能得到我正在寻找的响应。但我仍然收到错误 IE first launch。

有什么想法吗?

谢谢!

【问题讨论】:

标签: powershell


【解决方案1】:

您是否在运行此脚本的机器上打开了 Internet Explorer?

Invoke-WebRequest 使用 Internet Explorer,并且通常在您至少打开一次并关闭运行一次弹出窗口之前它无法工作。

您可以通过添加-UseBasicParsing 开关来解决此问题,您需要将其添加到Invoke-WebRequest所有 个实例中(不仅仅是第一个......我数了两个,忽略在您的示例中注释掉了一个。)

或者,您可以在 IE 中use a GPO to disable 第一个运行的东西。

【讨论】:

  • 我已经登录了所有 4 个盒子并打开了 IE。甚至注销并重新登录只是为了确保不是个人资料有问题。我将尝试将 -UseBasicParsing 添加到其他命令中。让我明白的是,其他系统管理员都不必登录到这些盒子,也不必添加 -UseBasicParsing 命令。这一定是权限问题吧?
  • 我从未见过与权限有关的错误消息(它非常明确地说明了原因并提供了特定的解决方案;))
【解决方案2】:

如果您使用管理员打开了 PowerShell 会话,那么您也必须使用管理员打开 IE 浏览器,否则它将无法相互识别。

【讨论】:

    猜你喜欢
    • 2010-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-26
    相关资源
    最近更新 更多