I am using Powershell version 2, so I cannot use Ping-Host as described here Is there a way to treat Ping-Host as logical in PowerShell?
I can use a test connection, i.e.
Test-Connection *ip_address* -count 1
I try to make it logical, but it does not work
if ($(test-connection server -count 1).received -eq 1) { write-host "blah" } else {write-host "blah blah"}
The server on which I can ping displays "blah blah" as if I could not carry it.
On the other hand, if I ping an unavailable server, I get an error message
Testing: failed to test connection to the computer server: Error due to lack of resources. In line: 1 char: 22 + if ($ (test-connection <<server-count 1) .received-eq 1) {write-host "blah"} else {write-host "blah blah"} + CategoryInfo: ResourceUnavailable : (server: String) [Test-Connection], PingException + FullyQualifiedErrorId: TestConnectionException, Microsoft.PowerShell.Commands.TestConnectionCommand
And in the end, he still displays blah blah.
How to fix?
powershell ping
Glowie
source share