Issue with using a loop with Test-netconnection

Hello all,

I am having problems getting the to return false when it cannot find an RPC connection to a machine. The snippet is below even if the port connection is successful and returns true it still goes to the else and reports issue with RPC. Any thoughts on this please ?

$connection = Test-netconnection -ComputerName $ComputerName -port 135
if ($connection -eq $true)
{
Write-Host “RPC Connection to Port 135 successful”

}

Else {"Issue with RPC "}

if((Test-NetConnection -ComputerName $ComputerName -Port 135).TcpTestSucceeded){'cool'}else{'uncool'}