Issue with using a loop with Test-netconnection

Welcome Forums General PowerShell Q&A Issue with using a loop with Test-netconnection

  • This topic has 1 reply, 2 voices, and was last updated 1 month ago by
Viewing 1 reply thread
  • Author
    • #220986
      Topics: 12
      Replies: 11
      Points: 156
      Rank: Participant

      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 “}

    • #221013
      Topics: 4
      Replies: 2231
      Points: 5,414
      Helping Hand
      Rank: Community MVP
      if((Test-NetConnection -ComputerName $ComputerName -Port 135).TcpTestSucceeded){'cool'}else{'uncool'}
Viewing 1 reply thread
  • You must be logged in to reply to this topic.