views:

77

answers:

2

I'd like to do something like this:

if (Ping-Host server1) { blah }

Anyone know of a simple way?

+3  A: 

Something like this?

if ($(Ping-Host server1 -count 1 -timeout 10).received -eq 1) { blah }
LukeH
Exactly like that. Thanks a lot.
serialhobbyist
+3  A: 

If you are on PowerShell 2.0 I would recommend using Test-Connection -Quiet. It returns a simple true or false indicating whether or not the host can be reached via ping. BTW one of the benefits of Test-Connection is it's built-in whereas ping-host isn't.

Keith Hill