Timestamps and file output

Select-Object doesn’t execute when Test-NetConnection fails. And if the machine is not reachable, it gives just a warning message as you get.

Above script will keep on looping until the system comes up, and returns the value $tnc. it will have the time when the ping succeeded. So you can add a check if it failed and save it in a variable, the return it along with $tnc using calculated property.

# Test-NetConnection here

if($tnc.TcpTestSuceeded -eq $flase){
    $FailedDuring = $tnc.TimeStamp
}

$tnc | Select-Object -Property @{
        Name = 'TimeStamp'
        Expression = $FailedDuring
    }, RemoteAddress, RemotePort, TcpTestSuceeded

Start-Sleep -Seconds 5