I am a novice when it comes to PS. Trying to figure out the best way to get this script to report that a server is unreachable instead of a exception error. It also still lists the service as running even though I am unable to reach the server from my computer.
Destination host unreachable is the result of the destination host not up or not responding to echo request (ping). Usually, (Firewalling) blocking echo reply (in response to echo request) is the default for servers. PowerShell Get-Service does not ping the host. It uses wsman service (HTTP/HTTPS) on port (5985/5986), so it was able to Get-Service running on the destination host.
To check for destination host unreachable either (a) ping the host or (b) use PowerShell (Test-Connection hostname) or (Test-Netconnection IP-address). I thought the purpose of your script was to get services if the host was up.
Here’s a code example:
$computer = 'UnreachableHost' if (Test-Connection -computername $computer -Quiet -Count 1) { # host reachable do stuff Write-host "Reachable" } else { # failed, log or whatever Write-host "Unreachable" }
Yes I want to add a check in the script to make sure the host is up before it tries to check for the services. Right now if I add a host to the list that is down (in this case an dummy host) it just spits out an exception error then still states that BITS is running on the host it can’t connect to.
I sort of have what you have suggested added in there and messing with it a bit but I can’t figure out how to get it to complete the service check after it tests the connection successfully.