Perform Automate Telnet Commands with PowerShell

Steps on how to perform automate telnet commands with PowerShell WASP (Windows Automation Snapin for PowerShell)

  1. Install Chocolatey Package Manager by following my previous post

  2. Install the WASP Module

#Install wasp
choco install wasp -y

#Copy the following modules to Windows PowerShell Module Path 
copy-item C:\ProgramData\chocolatey\lib\wasp -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules
copy-item C:\ProgramData\chocolatey\lib\autoload -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules
copy-item C:\ProgramData\chocolatey\lib\reflection -Recurse -Destination C:\Windows\system32\WindowsPowerShell\v1.0\Modules

#Import wasp module 
Import-Module wasp
  1. Launch Command Prompt with Administrator Right and set the focus Windows to the CMD
#Start cmd 
Start-Process -FilePath "cmd.exe" -Verb runas
Start-Sleep -Seconds 2

#Set Focused Windows
$window = Select-UIElement | ? Name -like "*cmd.exe"
  1. Prepare the commands that will be send to CMD automatically
#Send Command to telnet windows - Example based on Telnet to Email Server using SMTP Commands 
$TelnetTo = "telnet mail.aventistech.info 25"
$Helo = "helo"
$MailFrom = "mail from:<[email protected]>"
$RcptTo = "rcpt to:<[email protected]>"
$Data = "data"
$Subject = "Subject:Email Testing"

$Commands = @($TelnetTo,$Helo,$MailFrom,$RcptTo,$Data,$Subject)
Foreach ($Command in $Commands) { 

    $window | Send-UIKeys $Command
    #Send Enter
    $window | Send-UIKeys "~"
    #Delay of 1 Second
    Start-Sleep -Seconds 1

}

#Send Email
$window | Send-UIKeys "~"
$window | Send-UIKeys "."
$window | Send-UIKeys "~"

#Exit SMTP telnet Session
$window | Send-UIKeys "quit"
$window | Send-UIKeys "~"
  1. Commands are executed with the output shown in CMD automatically

WASP-01

Leave a Comment

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

Scroll to Top