This Script can be used to automate the configuration backup of network devices using SSH and TFTP Server.
It’s a common issue to backup cisco switch configuration through PowerShell as the default login will not have the privilege to run the switch backups but this is not affected in HP switches.
This script will help you to pass the enable mode password as a stream for Cisco switches.
Prerequisites
- Window’s PowerShell version 5 and above
- A TFTP server
- SSH should be enabled on all the switches
- Posh-SSH module should be installed on Windows PowerShell
- Configure the root folder for TFTP service, for me its “C:\Users\Test\Desktop\RK\”
- Create a notepad file in the root location and rename to switches, Input the management IP of all the required switches into this notepad file.
- Open an administrative PowerShell and execute the below command to encrypt the switch password. Read-Host ‘Enter Password:’ | ConvertTo-SecureString -AsPlainText -Force | ConvertFrom- SecureString | Out-File "C:\temp\password.txt
- Copy the password.txt file to “C:\Users\Test\Desktop\RK\ "
- For configuring TFTP server using Tftpd64 in Windows- http://techzain.com/how-to-setup-tftp-server-tftpd64-tfptd32-windows/
- To install Posh-SSH module - https://www.powershellgallery.com/packages/Posh-SSH/2.0.2
- To Upgrade PowerShell version - https://docs.microsoft.com/en-us/powershell/wmf/5.1/install-configure
- Download the PowerShell script from below Github repository. https://github.com/Renjeeshrk/Powershell-Scripts
- Update the below values in Script
- $tftp_server = <TFTP server IP>
- $username = < Switch User name >
- $pwfile =<path to encrypted password file>
- $switches_array = <Change the path to input file>
- $stream.Write("%password%`n") ( Replace the %password% with enable mode password)
- Note: Replace the folder path of TFTP root for all the required areas
- Run the script from PowerShell. PS>.\Network_switch_auto_backup.ps1
- Output will be saved in the root folder. \2019\June\07122018\xx.xx.xx.xx\running-config.cfg \2019\June\07122018\ xx.xx.xx.xx\\startup-config.cfg
No comments:
Post a Comment