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
Last published date
Overview
Product section
Resolution
Method 1:
- Open PowerShell
- 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:
- Use the script bellow to check if the port is open.
- Replace IP_Address_Server with the address of the server you are interested in.
- Replace port with the port to check (for example: 17777).
- 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.