Reputation: 51
Recently promoted to Systems Admin and am really just getting setup. We've got a powershell script we use to check some services. Seems to work for all the other admins. I'm thinking it is permissions at this point but wanted to check here to see if I was missing anything.
Powershell Script
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
The output I get
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
Two things to note.
I have logged onto all four boxes with the same account I am running the powershell script. I'm right clicking and run as other user. The username I enter this is what I've logged onto all 4 servers with and made sure IE has been opened.
If I add -UseBasicParsing after "$Check = Invoke-WebRequest -Uri http://$Server/ServerService/ServerCalculator.svc" I am able to get the response I am looking for. But I still receive the error IE first launch.
Any ideas?
Thank you!
Upvotes: 1
Views: 12471
Reputation: 1
If you opened your PowerShell session with admin then you have to open the IE browser with admin too or else it won't recognize each other.
Upvotes: 0
Reputation: 1946
Have you opened up Internet Explorer on the machine(s) from which this script is running?
Invoke-WebRequest
uses Internet Explorer, and often it can't work until you've opened it at least once and dismissed the run-once pop-up.
You can get around this by adding the -UseBasicParsing
switch, which you need to add to all instances of Invoke-WebRequest
(not just the first one... I count two, ignoring the commented out one, in your sample.)
Alternatively, you can use a GPO to disable that first run thing in IE.
Upvotes: 6