I have a dynamic list of server names coming from a report on an internal website. I'm looking to have PowerShell get this list from URL, then use it as a variable that I can cycle through.
Currently, this is what I have.
$servers = Invoke-WebRequest -URI http://myserver/hostgroup.php?hostgroup=test | Select -expand Content
This returns a simple list, such as "SERVER1","SERVER2","SERVER3",. I want to loop through this list to run reports on. Here's a simple foreach as a starting point (which doesn't work).
foreach ($s in $servers) {
if(Test-Connection -Quiet $s -Count 1) {
Write-Host "Online"
} else {
# connection test failed
Write-Host "`a`n" $s "is unreachable" -ForegroundColor Red
}
}
The output I receive looks like it's using the whole string as the server name, and it's not breaking it down.
Here's the output.
"SERVER1","SERVER2","SERVER3", is unreachable