【发布时间】: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