PowerShell - Check Host Connectivity

function global:Check-Host
    {
    param
        (
        [Parameter(Mandatory=$true, ParameterSetName="hostname", Position=0)]$hostname,
        [Parameter(Mandatory=$false, ParameterSetName="port", Position=1)]$port
        )
    
    $this_ping_result = (Test-NetConnection -ComputerName $hostname)

    if ($port -ne $null)
        {
        $this_tcp_result = (Test-NetConnection -ComputerName $hostname -Port $port)
        }
    else
        {
        $port = "---"
        }

    write-host "Host: $hostname Ping: " -NoNewline

    if ($this_ping_result.PingSucceeded -eq $true)
        {
        Write-Host "UP   " -NoNewline -ForegroundColor Green
        }
    else
        {
        Write-Host "DOWN " -NoNewline -ForegroundColor Red
        }

    Write-Host "Lookup: " -NoNewline

    if ($this_ping_result.NameResolutionSucceeded -eq $true)
        {
        Write-Host "UP   " -NoNewline -ForegroundColor Green
        }
    else
        {
        Write-Host "DOWN " -NoNewline -ForegroundColor Red
        }

    if ($port -ne "---")
        {
        Write-Host "TCP port $port : " -NoNewline

        if ($this_tcp_result.TcpTestSucceeded -eq $true)
            {
            Write-Host "UP   " -ForegroundColor Green
            }
        else
            {
            Write-Host "DOWN " -ForegroundColor Red
            }
        }
    else
        {
        Write-Host "TCP not checked."
        }
    }