fleschutz / PowerShell

500+ PowerShell scripts (.ps1) for every system!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ping Check: Divide by 0

italianoaj opened this issue · comments

Perhaps adding a check in the ping test, in the event that there are 0 successes, doesn't throw an exception.
IE:

if($successCount -eq 0){
    $avg = 0
}else{
    $avg /= $successCount
}

Food for thought.

You're perfectly right! I missed that point. Now, I have changed this as follows:

        if ($successCount -eq 0) {
                Write-Host "⚠️ Offline ($lossCount/$lossCount loss)"
        } else {
                $avg /= $successCount
                Write-Host "✅ Ping latency is $($avg)ms average ($($min)ms...$($max)ms, $lossCount loss)"
        }