Answered by:
Error in My PS script

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 helpRegards,
Thursday, September 13, 2018 7:39 AM
Answers
-
Try this:
$CiscoDevice`:running-config
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Thursday, September 13, 2018 9:43 AM
- Marked as answer by azuriste Thursday, September 13, 2018 2:36 PM
Thursday, September 13, 2018 8:04 AM
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
- Proposed as answer by LeeSeenLiMicrosoft contingent staff Thursday, September 13, 2018 9:43 AM
- Marked as answer by azuriste Thursday, September 13, 2018 2:36 PM
Thursday, September 13, 2018 8:04 AM -
i will try it and i will tell you .thanksThursday, September 13, 2018 8:08 AM
-
thanks , its workingThursday, September 13, 2018 2:36 PM