Monday, 22 January 2018

Telnet check using script for multiple systems

Note: Change/Mention your Port numbers of the systems. Example ip's mentioned below :

$test = @('1.2.3.4:443','5.6.7.8:443','9.10.11.12:443','13.14.15.16','17.18.19.20:443')

Foreach ($t in $test)
{
  $source = $t.Split(':')[0]
  $port = $t.Split(':')[1]
 
  Write-Host "Connecting to $source on port $port"

  try
  {
    $socket = New-Object System.Net.Sockets.TcpClient($source, $port)
  }
  catch [Exception]
  {
    Write-Host $_.Exception.GetType().FullName
    Write-Host $_.Exception.Message
  }

  Write-Host "Connected`n"

}