Telnet equivalent in Powershell to test if port is reachable

Powershell doesn’t come with telnet by default, however you can use the following command to quickly connect to a TCP server in a Powershell window.

1. Test-NetConnection

The simplest option is to use the command “Test-NetConnection”. With this command you can specify a computername (or IP address) and port to check if a connection can be made. Use the following command:

Test-NetConnection -ComputerName mycomputer.local -Port 80

It should give the following output, the last line “TcpTestSucceeded” indicates whether the connection was made succesfully or not.

ComputerName     : mycomputer.local
RemoteAddress    : 192.168.1.15
RemotePort       : 80
InterfaceAlias   : LAN
SourceAddress    : 192.168.1.10
TcpTestSucceeded : True

2. TcpClient object

The following command is a bit longer, but the benefit is that you can use this to create a TcpClient object to actually send TCP messages via a Powershell script.

Open up a Powershell window and enter the following command:

New-Object System.Net.Sockets.TcpClient("google.com", 80)

If the TCP connection is succesful, you should see the following output:

Client              : System.Net.Sockets.Socket
Available           : 0
Connected           : True
ExclusiveAddressUse : False
ReceiveBufferSize   : 65536
SendBufferSize      : 64512
ReceiveTimeout      : 0
SendTimeout         : 0
LingerState         : System.Net.Sockets.LingerOption
NoDelay             : False

If you do not see anything or the screen hangs, it most likely indicates a timeout.

Note: you cannot send any commands over the TCP connection this way (for that you would need to create a Powershell script). However for quick connect tests this method is sufficient.

Published
Categorized as Powershell

By Leendert de Borst

Freelance software architect with 10+ years of experience. Expert in translating complex technical problems into creative & simple solutions.

Leave a comment

Your email address will not be published. Required fields are marked *