PowerShell Telnet and Alternatives to Telnet Command

Telnet protocol is used to establish a remote connection to remote computer. Telnet provides access to a command-line interface on remote computer. Because of security concerns, Telnet client feature disabled by default on all version of Windows operating system. There are different alternatives to PowerShell Telnet to test remote computer connection if you don’t want to enable Telnet Client feature.

If you try to run Telnet in PowerShell, it will throw exception as ‘Telnet’ is not recognized as the name of cmdlet.

In this article, I will explain you how to use PowerShell Telnet and PowerShell Telnet alternative to test remote host connection over port.

In all version of Windows Operating System, Telnet client is disabled by default because of security reason.

Lets understand PowerShell Telnet alternatives to test remote computer connection.

Using Test-NetConnection to Test Connectivity

PowerShell Test-NetConnection cmdlet is used to test connectivity with remote computer and get diagnostics information about connection.

Syntax

Test-NetConnection
    [[-ComputerName] <String>]
    [-TraceRoute]
    [-Hops <Int32>]
    [-InformationLevel <String>]
    [<CommonParameters>]

To test ping connection to remote host, use PowerShell Test-NetConnection command as below

Test-NetConnection -ComputerName 192.168.0.6 -InformationLevel "Detailed" -Port 3389

In the above command, PowerShell Test-Connection command test ping connectivity with remote computer name specified by ComputerName and Port 3389.

It returns detailed diagnostic information about remote computer connectivity as given below

ComputerName            : 192.168.0.6
RemoteAddress           : 192.168.0.6
RemotePort              : 3389
NameResolutionResults   : 192.168.0.6
MatchingIPsecRules      :
NetworkIsolationContext : Private Network
IsAdmin                 : False
InterfaceAlias          : Wi-Fi
SourceAddress           : 192.168.0.6
NetRoute (NextHop)      : 0.0.0.0
TcpTestSucceeded        : True

If PingSucceeded is true, it means remote computer is reachable over Port 3389 else not reachable. PowerShell Test-Connection test port without telnet.

Using System.Net.Sockets.TcpClient to Test Connectivity

Microsoft .Net System.Net.Sockets.TcpClient provides telnet connectivity to remote host on specified port number.

To test connection with remote computer, use System.Net.Sockets.TcpClient method as below

New-Object System.Net.Sockets.TcpClient("192.168.0.6", 3389) 

In the above command, TcpClient method takes remote computer IP address and port number to test connection.

It returns detailed diagnostics information about test connection with remote computer over port number as below

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

In the above output,

Connected : True, if connection to remote computer over port is successful

Connected: False, if connection to remote computer over port is unsuccessful.

Cool Tip: How to use Get-AdDomainController to get domain controller in PowerShell!

Using PowerShell Telnet to Test Connection

As Telnet client is disabled by default on Windows 10 or all windows version. We need to enable Telnet client before using it.

There are three different ways to enable Telnet client in Windows as given below

Install Telnet Client using Command Prompt (cmd)

To install Telnet client using cmd, open command prompt with run as administrator.

Run below command on cmd to enable Telnet client feature using dism

dism /online /Enable-Feature /FeatureName:TelnetClient

In above command, dism command used to repair or modify Windows installation media and its feature.

Using Enable-Feature, it takes TelnetClient as FeatureName and enable Telnet client on Windows operating system to test port.

Install Telnet Client using PowerShell

To install Telnet client using PowerShell console, open terminal with run as administrator.

Install-WindowsFeature cmdlet require ServerManager to be installed. Install module using below command

Import-Module ServerManager

Run below command in PowerShell terminal to enable Telnet in PowerShell.

Install-WindowsFeature -name "Telnet-Client"

In above command, using Install-WindowsFeature, it takes Telnet-Client as feature name and on run it enable Telnet in PowerShell to test connection with remote host over port.

Conclusion

Telnet command is very useful for system administrator to test connection over remote computer and test port if it used or block port if they are not in use.

If PowerShell Telnet client not enabled, you can enable it using dism or Install-WindowsFeature command. If you don’t want to enable Telnet client feature, there are other telnet alternative to test connection to remote host using PowerShell Test-Connection and System.Net.Sockets.TcpClient.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment