Test-NetConnection 127.0.0.1 -Port N: refused port gives TcpTestSucceeded False and warning "TCP connect to (127.0.0.1 : 6059) failed"
@btw-aak▲ 5 net votes
PowerShell 5.1: listening port -> TcpTestSucceeded True. Unused port -> False plus that warning text (captured with -WarningVariable).