Powershell: Test connection on computer port | I do stuff sometimes.

Ramblings about things.

Powershell: Test connection on computer port

I use this if telnet is not layin’ around – mainly to test if a computer is reachable on a specific TCPport.

try
  {
   $portquery = New-Object System.Net.Sockets.TcpClient("SERVERNAME", PORTNUMBER)
   $portquery.Close()
   return $true
  }
catch [system.exception]
  {
   return $false
  }
  • F


  • Archives