cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2788
Views
0
Helpful
4
Replies

Powershell Script to backup 2960 Stack Full Configuration

Azuriste
Level 1
Level 1

Hello ,

Im looking for a powershell script to backup my 2960 switch Stack configuration .

I prefer follow a bestpractices.

 

Regards,

4 Replies 4

omz
VIP Alumni
VIP Alumni

Powershell ... really? :) I prefer using Python but .. anyhow have a look at this post. 

https://www.sherweb.com/blog/fun-with-powershell-plink-cisco-ios-and-powershell/

 

I think PS is complicated here .could you let me know how with perl please ?

Regards

Sorry, I don't know perl :) 

**BANTER Start** showing your age ;) **BANTER End**

But have look here - 

https://thwack.solarwinds.com/thread/19748

 

If you fancy giving Python a go. 

Prerequisites:

- Install Python 2.7, Paramiko and getpass 

import paramiko
import time
import getpass
import os
import sys

#IP = '1.1.1.2'
#USER = raw_input("Username : ")
#PASS = getpass.getpass("Password : ")
#ENABLE = getpass.getpass("Enable : ")

# ONLY FOR TESTING HARD CODE. UNCOMMENT ABOVE AND DELETE  BELOW AFTER TESTING
IP = '1.1.1.2'
USER = 'cisco'
PASS = 'cisco123'
ENABLE = 'cisco123'

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(IP, port=22, username=USER, password=PASS, look_for_keys=False,allow_agent=False)
remote = ssh.invoke_shell()
remote.send('term len 0\n')
remote.send('enable\n')
remote.send('%s\n' % ENABLE)
time.sleep(1)

remote.send('sh run\n')
time.sleep(10)

output = remote.recv(65000)
print output

timestr = time.strftime("%Y%m%d-%H%M")

with open('{}-{}.txt'.format(IP, timestr), 'a') as config:
    config.write(output)

 

 

 

 

Just for your info you may want to look at Netmiko (written by the same guy) which uses Paramiko but takes out some of the lower level stuff for managing network devices. 

 

So your code in Netmiko would be - 

 

from netmiko import ConnectHandler

 

swp = ConnectHandler(device_type='cisco_ios', ip=IP, username=USER, password=PASS, secret=ENABLE)

swp.enable()

output = swp.send_command('sh run') 

 

print output 

 

Jon

Review Cisco Networking products for a $25 gift card