Author Posts

April 20, 2018 at 9:06 pm

Hi people

Someone has needed to connect and send many commands to a switch/router? My ideia would be a txt file with hosts list and other file with command.

I have part of that file but I need to inform the host and commands individually.

The script have a function named get-telnet and we call that like below:

Get-Telnet -RemoteHost "1.1.1.1" -Commands "user","password","stuff","stuff","config","ip snmp-server community comm rw ","sntp client","no sntp server all","sntp server 2.2.2.2","clock timezone BR -3","end","copy runn startup" -OutputPath  "C:\Users\Scripts\output.txt" -WaitTime 1000

I found the function researching into web. Here the source: https://superuser.com/questions/1209098/issue-with-telnet-connection-through-get-telnet-script

Thank you for the help.
Thank you.

April 20, 2018 at 11:09 pm

Not really sure what your question is?

Looking at your example do you mean that the remote hosts are in one file and the commands are in another?
And you want to grab those two files as a source to use the Get-Telnet with?
If so are there multiple hosts that are going to use the same commands or are they 1:1?

April 21, 2018 at 4:28 am

Hi Fredrik,

Thanks for your reply. Actually I need (would like to) get de hosts and commands both in a files, but, if that is not possible, to get the host list and the commands into script will be works fine.

rc.

April 21, 2018 at 4:59 am

Then, I suppose the simplest approach would be to have two files:

$RemoteHosts = Get-Content '//path/to/hosts/file.txt'
$Commands = Get-Content '//path/to/commands/file.txt'

$RemoteHosts | ForEach-Object {
    Get-Telnet -RemoteHost $_ -Commands $Commands
}

This assumes you are supplying the same commands to each remote host.