Network Management

Use PowerShell to test that a port is open on a server

This article describes how to use PowerShell to TCP ping test a port on a server without using Telnet.

First published date

10/22/2018 6:24 PM

Last published date

7/11/2025 7:15 AM

Overview

TCP pings can be useful for determining if services are up and running or if security is blocking data. 

Product section

Orion Platform

Resolution

Method 1:

  1. Open PowerShell
  2. Modify example command below, replacing IP address (or hostname) and port       
Test-NetConnection -ComputerName 192.168.1.1 -Port 443
Test-NetConnection -ComputerName hostname -Port 443
 

This performs a ping test and TCP port test. If port test succeeds, it will show "TcpTestSuceeded: True". 
Note: Host names and website names may also be used in place of IP address
​​​​

Method 2:

  1. Use the script bellow to check if the port is open.
  2. Replace IP_Address_Server with the address of the server you are interested in.
  3. Replace port with the port to check (for example: 17777).
  4. Save this script in a text file as porttest.ps1 and run in PowerShell.
-- Scripts are not supported under any SolarWinds support program or service.
-- Scripts are provided AS IS without warranty of any kind. SolarWinds further
-- disclaims all warranties including, without limitation, any implied warranties
-- of merchantability or of fitness for a particular purpose. The risk arising
-- out of the use or performance of the scripts and documentation stays with you.
-- In no event shall SolarWinds or anyone else involved in the creation,
-- production, or delivery of the scripts be liable for any damages whatsoever
-- (including, without limitation, damages for loss of business profits, business
-- interruption, loss of business information, or other pecuniary loss) arising
-- out of the use of or inability to use the scripts or documentation.

$ipaddress = IP_Address_Server 
$port = port 
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
if ($connection.Connected) {
     Write-Host "Success" 
} else { 
     Write-Host "Failed" 
}


Your organization should internally review and assess to what extent PowerShell is incorporated into your environment. This is especially important when importing scripts from third parties, including content posted by other customers in the SolarWinds THWACK online community.