如何通过plink在Cisco CLI中成功执行“清除计数器”命令?

问题描述

我使用以下PowerShell脚本在远程Cisco设备上执行简单的Cisco CLI命令,而没有任何问题:

 function Invoke-PlinkCommandsIOS { 
     param (
        [Parameter(Mandatory=$true)][string] $Host,[Parameter(Mandatory=$true)][System.Management.Automation.PSCredential] $Credential,[Parameter(Mandatory=$true)][string] $Commands,[Switch] $ConnectOncetoAcceptHostKey = $false
    )
     $PlinkPath="$PSScriptRoot\plink.exe"
    $commands | & "$PSScriptRoot\plink.exe" -ssh -2 -l $Credential.GetNetworkCredential().username -pw "$($Credential.GetNetworkCredential().password)" $Host -batch
 } 

但是,我不确定如何在远程Cisco设备上成功执行clear counters命令,因为此命令还需要处理以下后续确认提示

Clear "show interface" counters on all interfaces [confirm]

我使用下面的命令行进行了实验,但是,它们都没有模拟为了正确地按enter键来处理随后的确认提示。非常感谢您能成功完成此操作。

Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands "clear counters\r\r"

Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands "clear counters`r`r"

Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands "clear counters`n`n"

Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands "clear counters\n\n"

Invoke-PlinkCommandsIOS -Host ace-dc1 -Credential $cred -Commands "clear counters`r`n"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)