loop until IP:port is responding loop until IP:port is responding powershell powershell

loop until IP:port is responding


The code above doesn't work because the until test only verifies if the result is not null. Test-NetConnection always returns an object(even with false as a status), so the test would always be "true", which means that your do { } scriptblock would only run once no matter what the result is. One solution would be to make the until test check one of the properties returned, like this:

do {  Write-Host "waiting..."  sleep 3      } until(Test-NetConnection $HOST -Port PORT | ? { $_.TcpTestSucceeded } )