powershell - Sending complex, multi-line command via plink to Cisco Router =Unexplained behavior -


i'm trying below part of code done in relatively condensed fashion (to plug in bigger script). don't have problems sending multiple commands way. however, there's that's causing multi-line command choke. syntax cisco comnmands appear correct. i'm not sure if i'm running kind of character limit or if need escape specific characters in $showintstatuscommands, nothing tried seems work.

this code:

$bgpinterface = "gigabitethernet0/2" $showintstatuscommands =  "`nterminal length 0`nsho int $bgpinterface | include reliability|errors`nsho log | include $date.*link-3-updown.*$bgpinterface`nexit" ($response = $showintstatuscommands | c:\windows\plink.exe -ssh -2 -l $credential.getnetworkcredential().username -pw $($credential.getnetworkcredential().password) $devicename -batch) 2>$null | out-null 

produces below when reveal contents of variables. $showintstatuscommands appears correct when echoes locally. notice, end of 3rd line cut off (number 2 character missing @ end). subsequent line weird residual of previous line, starts $nclude.

ps c:\users\mkanet\desktop\test> $response cisco-router# cisco-router#terminal length 0 cisco-router#sho int gigabitethernet0/2 | include reliability|errors     reliability 255/255, txload 1/255, rxload 1/255  0 input errors, 0 crc, 0 frame, 0 overrun, 0 ignored  0 output errors, 0 collisions, 3 interface resets  cisco-router#sho log | include jul 17.*link-3-updown.*gigabitethernet0/  $nclude jul 17.*link-3-updown.*gigabitethernet0/2  cisco-router# cisco-router#exit ps c:\users\mkanet\desktop\test> $showintstatuscommands terminal length 0 sho int gigabitethernet0/2 | include reliability|errors sho log | include jul 17.*link-3-updown.*gigabitethernet0/2 exit

when write variable in non-global scope (like script or function scope), powershell not modify higher level scoped variables of same name. iow $response = 'foo' create local copy of $response variable , assign 'foo' it. if intent modify global variable $response change line $global:response = ... see in $global:response residual, previous tinkerings.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -