This function will not work on PowerShell Core. But you should probably be using Test-Connection regardless.

A lot of my scripts use Active Directory to create lists of servers. Unfortunately, AD often contains decommissioned computer objects, which can cause certain queries to time-out

I wrote this quick function so that before running WMI queries against a server, we could do a quick check to see whether it was online.

function IsPingable {

    Pings a server and returns TRUE or FALSE.
    Uses WMI to ping a server, and returns TRUE if a status code of 0 is returned, otherwise returns FALSE. Useful for quick checks to see if a server exists and is online.
    .PARAMETER Computer
    The computer's Hostname, FQDN, or IP to be pinged.
    IsPingable -Computer "SERVER01"
    Pings SERVER01
    Ben Neise 12/03/13
    param (
    $objPing = Get-WmiObject -Class "Win32_PingStatus" -Filter "Address='$Computer'"
    if ($objPing.StatusCode -eq 0){
        $boolPingable = $true
    else {
        $boolPingable = $false

    return $boolPingable