$pingResults = Ping-Host -HostName $ComputerName -Count 2 -Quiet -ErrorAction SilentlyContinue
if ($pingResults.received -gt 0)
{
# Do something
}
if ($pingResults.received -gt 0)
{
# Do something
}
And then I discovered test-connection! Now for simple quick tests we can just do:
if (Test-Connection $ComputerName -count 2 -quiet)
{
#Do something
}
{
#Do something
}
For larger groups of computers I'll still use PSCX's Ping-Host cmdlet due it's ability to ping all specified hosts asynchronously and it's speed. You've updated to PSCX 2.0, right? But Test-Connection is the right tool at the right price for quick connectivity checks. Learn more about Test-Connection with Get-Help Test-Connection or on Technet.