Wednesday, May 23, 2012

Automate HP Switch Config Backup

Below is a VB Script that I wrote that will open a command prompt, telnet into an HP Procurve switch and copy its runnung config to a TFTP server.

In order for this script to work, you will need a text file will the IP addresses of your switches on a seperate line. You will also need to edit the lines that I have maked in RED.

*Note: Do not click off of the command prompt window while this script is running or you are going to get alot of text where you don't want it and you will not get your switch configs.

'--------Start Of Script--------
Option Explicit
On Error Resume Next
Dim WshShell, strIP, strTFTP, strFile, strPassHP
Dim filesys, filetxt

strFile = "File Name"
strTFTP = "Your TFTP Server Address"
strPassHP = "Your HP Procurve Password"

'Opens IP address file for reading
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile(strFile, ForReading, True)

'Opens the command prompt
set WshShell = CreateObject("WScript.Shell") "cmd.exe"
WScript.Sleep 1000

Do While Not filetxt.AtEndOfStream

strIP = filetxt.ReadLine

set WshShell = Nothing
set filesys = Nothing

Function Copy(strIP)

WshShell.SendKeys "telnet "& strIP
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000 
WshShell.SendKeys "p"
WshShell.SendKeys strPassHP
WshShell.SendKeys ("{Enter}") 
WshShell.SendKeys "copy running-config tftp " & strTFTP & " " & strIP & ".txt" 
WshShell.SendKeys ("{Enter}")
WshShell.SendKeys "^z"
WshShell.SendKeys "^z"
WshShell.SendKeys "y"
WScript.Sleep 2000
WshShell.SendKeys ("{Enter}")
End Function
'--------End Of Script--------


  1. Easier like this :
    pscp -scp -l USERNAME -pw PASSWORD -2 c:\switch.cfg

  2. Thanks, this works perfect.