I have this script to test a specific site. It works but not the way I want to. After the "try" parameter, the variable $hostpc
is not getting called.
This is the output I'm getting:
Testing Server:
Web Ping on Succeeded.
It should be something like this:
Testing Server: servername
Web Ping on servername Succeeded.
Script
$servers = Get-Content 'some.txt'
Foreach ($hostpc in $servers) {
Invoke-Command $hostpc -ScriptBlock {
try {
write-host "Testing Server: $hostpc"
$request = [System.Net.WebRequest]::Create("some web site")
$response = $request.GetResponse()
Write-Host "Web Ping on $hostpc Succeeded." -foregroundcolor Yellow
} catch {
Write-Host ("Web Ping on $hostpc FAILED!!! The error was '{0}'." -f $_)-foregroundcolor Red
}
}
}