Cisco Configuration backup with Windows Script.

Posted by Jeff on Server Fault See other posts from Server Fault or by Jeff
Published on 2011-01-12T16:54:35Z Indexed on 2011/01/12 17:55 UTC
Read the original article Hit count: 283

We have a client with a lot of Cisco Devices and we would like to automate the backups of these devices through telnet. We have both 2003 and 2008 servers and ideally use tftp to back it up.

I wrote this:

Set WshShell = WScript.CreateObject("WScript.Shell") 
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim ciscoList
ciscoList = "D:\Scripts\SwitchList.txt"

Set theSwitchList = fso.OpenTextFile(ciscoList, 1)

Do While theSwitchList.AtEndOfStream <> True
cisco = theSwitchList.ReadLine
Run "cmd.exe"
SendKeys "telnet " 
SendKeys  cisco
SendKeys "{ENTER}"
SendKeys "USERNAME"
SendKeys "{ENTER}"
SendKeys "PASSWORD"
SendKeys "{ENTER}"
SendKeys "en"
SendKeys "{ENTER}"
SendKeys "PASSWORD" 
SendKeys "{ENTER}" 
SendKeys "copy startup-config tftp{ENTER}"
SendKeys "(TFTP IP){ENTER}"
SendKeys "FileName.txt{ENTER}"
SendKeys "exit{ENTER}" 'close telnet session' 
SendKeys "{ENTER}" 'get command prompt back 
SendKeys "{ENTER}"
SendKeys "exit{ENTER}" 'close cmd.exe
On Error Resume Next
  WScript.Sleep 3000
Loop
Sub SendKeys(s)
  WshShell.SendKeys s
  WScript.Sleep 300
End Sub

Sub Run(command)
  WshShell.Run command
  WScript.Sleep 100 
  WshShell.AppActivate command 
  WScript.Sleep 300 
End Sub

But the problem with this is the sendkeys are sent to the console session, I'm trying to find a solution that would not require a user to be logged in.

Does anyone have any ideas? I have some knowlage of VBS, PowerShell and a pretty good grasp on batching.

© Server Fault or respective owner

Related posts about windows-server-2008

Related posts about windows-server-2003