The problem is that you are referencing $computers and not $server.
$reply = Invoke-WebRequest http://$server":1055" | Select-Object statusdescription
Pregunta
Here is what I am trying to accomplish.
Instead of the script grabbing each ip in the servers.txt file .. it is putting them all together and failing. What am I missing here? As you can see below it is just putting all the ips in the $server variable.
Here is the error.
Invoke-WebRequest : Cannot bind parameter 'Uri'. Cannot convert value "http:// Computer1 Computer2 Computer3:1055" to type "System.Uri". Error: "Invalid URI: The
ERROR: hostname could not be parsed."
And the code is below
$Computers = Get-Content -Path C:\temp\servers.txt
foreach ($Server in $computers) {
$reply = Invoke-WebRequest http://$computers":1055" | Select-Object statusdescription
if ($reply.statusdescription = "OK")
{
$Sheet1.Cells.Item($intRowSoft, 1) = $server
$Sheet1.Cells.Item($intRowSoft, 2) = "YES"
$intRow = $intRow + 1
}
else {
$Sheet1.Cells.Item($intRowSoft, 1) = $server
$Sheet1.Cells.Item($intRowSoft, 2) = "NO"
$intRow = $intRow + 1
}
}
Solución
The problem is that you are referencing $computers and not $server.
$reply = Invoke-WebRequest http://$server":1055" | Select-Object statusdescription