locked
Error in My PS script RRS feed

  • Question

  • Hello , 

    this script for backup the configuration of switch cisco : 

    $CiscoDevices = Get-Content -Path c:\switchs.csv
    $Date = Get-Date -Format “dd-MM-yyyy”
    $Username = “"
    $Password = “”
    $BackupPath = “C:\BKP”
    New-Item $BackupPath\$Date\ -type directory
    Start-Transcript -path $BackupPath\$Date\$Date.log -append

    foreach ($CiscoDevice in $CiscoDevices){

    echo y | pscp.exe -scp -l $Username -pw $Password -v $CiscoDevice:running-config $BackupPath\$Date\ | out-host -verbose


    }

    Stop-Transcript

    -------

    My Problem here : $CiscoDevice:running-config 

    the varibale $CiscoDevice got an IP address .so , when i do $CiscoDevice:running-config its not working , but when i do 192.168.1.25:running-config it works 

    what could be the problem ?

    this was the error :

     

    scp.exe : pscp: unknown option "-config"
    Au caractère Ligne:1 : 1
    + pscp.exe -scp -l $Username -pw $Password -v $CiscoDevice:running-conf ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (pscp: unknown option "-config":String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError

          try typing just "pscp" for help

    Regards,

    Thursday, September 13, 2018 7:39 AM

Answers

All replies

  • You need a space after the "-"

    $CiscoDevice:running -config $BackupPath\$Date\


    \_(ツ)_/

    Thursday, September 13, 2018 7:52 AM
  • running-config is one command in cisco devicesand it can not be running -config
    it works with 192.168.1.25:running-config   !

    Regards

    Thursday, September 13, 2018 7:58 AM
  • Try this:

    $CiscoDevice`:running-config

    Thursday, September 13, 2018 8:04 AM
  • i will try it and i will tell you .thanks
    Thursday, September 13, 2018 8:08 AM
  • thanks , its working
    Thursday, September 13, 2018 2:36 PM