2017-10-10 218 views
0

最近升级到Systems Admin,我真的只是设置。我们有一个我们用来检查一些服务的powershell脚本。似乎适用于所有其他管理员。我认为这是在这个时候的权限,但想在这里查看我是否缺少任何东西。Invoke-WebRequest错误

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第一次启动。

任何想法?

谢谢!

+0

http://wahlnetwork.com/2015/11/17/solving-the-first-launch-configuration-error-with-owowhells-invoke-webrequest-cmdlet/ – Aravinda

+0

https://stackoverflow.com/questions/ 38005341/-response-content-can-the-parsed-the-internet-explorer-engine-is-no – Aravinda

回答

0

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

Invoke-WebRequest使用Internet Explorer,通常它不能工作,直到您打开它至少一次,并解散了运行一次弹出窗口。

您可以通过添加-UseBasicParsing开关,你需要添加到Invoke-WebRequest(不只是第一个所有情况下解决这个问题......我算二,忽略了注释掉,您的样本。 )

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

+0

我已登录到所有4个盒子并打开IE。甚至注销并重新开始,以确保它不是不可靠的配置文件。我会尝试在-UseBasicParsing上添加其他命令。 什么让我不是其他系统管理员必须登录到框,也不需要添加-UseBasicParsing命令。 这必须是一个权限的事情正确吗? – Ryan

+0

我从来没有见过与权限有关的错误消息(这是相当明确的原因,并提供了一个特定的解决方案的原因;)) – Windos