Take backup of switch configuration using powershell

Snehasish Nandy 1 Reputation point
2021-12-16T11:37:06.93+00:00

Hi All,

I am trying to automation the below steps through powershell

![158224-image.png]2

I have written the below code to do this, but when I am executing the command it is going to a hang mode and not getting any output.

# Create a variable based on the date in the format of YYYYMMDD  
$DateStamp = Get-Date -UFormat "%Y%m%d"  

# Set the location of the Putty Link executable  
$PLinkBin = "C:\Program Files\PuTTY\plink.exe"  

# Access details for destination FTP server  
$SFTPServer = "10.12.8.13"  
$FTPUser = ""  
$FTPPass = ""  

# Access details for the FC switches. All switches must have the same login credentials  
$FCSwitches = @("192.168.7.1")  
$FCSwitchUser = ""  
$FCSwitchPass = ""  

#Loop through each of the FC switches, creating a file name in the formate of Name-YYYYMMDD.txt.  
#Login to each switch and run the configupload command to backup to the FTP server.  
ForEach ($FCSwitch in $FCSwitches){  
$BackupFileName = "/home/Storage/Monthly_Backup/$FCSwitch-$DateStamp.txt"  
$BackupCommand = "configupload -all -sftp $SFTPServer,$FTPUser,$BackupFileName,$FTPPass"  
#& $PLinkBin -pw $FCSwitchPass $FCSwitchUser@$FCSwitch $BackupCommand  
@(echo y | & $PLinkBin -pw $FCSwitchPass $FCSwitchUser@$FCSwitch $BackupCommand)  
}  

Please if anyone can help me out on this

below command I am trying. this time it is coming out of prompt but file not getting created. no error also

configupload -all -p sftp 10.1.8.13,UserName,/home/Storage/Monthly_Backup/192.168.1.7-20211215.txt,password  

when I am trying same command from putty, it is asking for password again. once I enter it is executing

158214-image.png

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,273 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 43,926 Reputation points
    2021-12-16T16:02:47.46+00:00

    Why not use "-batch" as a parameter for plink.exe? That suppresses all interactive prompts.

    plink-options.html