Note: This blog has moved! New location vineethac.blogspot.com
In this article, I will briefly explain how to back up the running configuration of Cisco switches to a TFTP server location using PowerShell.
Prerequisites:
- A TFTP server should be configured and running.
- PowerShell module Posh-SSH should be installed on the node from which the script is running.
Workflow:
- Collect credentials to SSH into the switch$creds = Get-Credential
- Create a new SSH session to the first switch in the list$sw_ssh = New-SshSession -ComputerName <Management IP of Cisco switch> -Credential $creds -Force -ConnectionTimeout 300
- Invoke the command to backup running config to TFTP server over the SSH session$cmd_backup = "copy running-config tftp://<IP of TFTP server>/config_backup.txt vrf management"Invoke-sshcommand -Command $cmd_backup -SSHSession $sw_ssh
You can schedule this PS script using a task scheduler so that the running configuration of switches can be backed up automatically on a daily basis or as per requirements. Hope this was useful. Cheers!
Related article:
Dell EMC switch configuration backup using PowerShell
Related article:
Dell EMC switch configuration backup using PowerShell
Vini, i am looking for a script to do multiple commands like show running conf, show VLAN and saved on one file
ReplyDeleteHi, the problem I get with above is that Cisco-ASA requires enable password. I am having problems automating authentication and getting into enable mode.
ReplyDeleteUsed below
ReplyDelete$ssh = New-SSHSession -ComputerName $device -Credential $cred
$DeviceBackup = Invoke-SshCommand -Command 'show start' -SSHSession $ssh
$DeviceBackup | out-file $device'.txt'
Got the error
Exception calling "EndExecute" with "1" argument(s): "An established connection was aborted by the server."
At C:\Users\v-sxt04\Documents\WindowsPowerShell\Modules\Posh-SSH\2.3.0\Posh-SSH.psm1:260 char:25
+ $Output = $_.cmd.EndExecute($_.Async)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SshConnectionException
Can you please help