Aug 10, 2018

Telnet on Windows with no Telnet Client using Powershell

If you do not have telnet client installed on your machine, you can use PowerShell to run a telnet command as shown below:

$Computer= "<server-name>";
$Port = <port-number>;
$nl = [Environment]::NewLine

Write-Host "$nl Trying to telnet to '$Computer' on Port: '$Port'$nl"
Try {
    $tcp = New-Object System.Net.Sockets.TcpClient
    $tcp.connect($Computer, $Port)
    Write-Host "Successfully connected to $Computer on Port: $Port"$nl -ForegroundColor Green
    $tcp.close() 
}
Catch {
    Write-Host "Could not connect to $Computer on Port: $Port"$nl -ForegroundColor Red
    Write-Host $_.Exception.Message -ForegroundColor Red
}

No comments: