Tuesday, January 02, 2007

Test connection to server

Small function to test connectivity to a server.

function test-connection {
    $pingtest = ping $args[0] -n 1
        if ($pingtest -match 'TTL=') {
        Write-Output $true
    } else {
        Write-host $false
    }
}

Usage:

test-connection MyServer01.domain.com

1 comment:

Anonymous said...

I would suggest to change the match to "TTL=" cause you can catch "TTL expired in transit",
which means that the request did not get to the server in time, probably because it couldn't get past the router.

"TTL=" means that your ping response was successful.