如何使用POWERSHELL SSH.net配置cisco路由器?

如何使用POWERSHELL SSH.net配置cisco路由器?,powershell,router,configure,ssh.net,Powershell,Router,Configure,Ssh.net,很好,这是我正在使用的代码: function escribe_log($dispositivo, $log, $comando){ $Fichero_Log = "C:\Modificacion_routers.log" $texto = $dispositivo $texto >> $Fichero_Log $texto = $log $texto >> $Fichero_Log $texto = $comando

很好,这是我正在使用的代码:

function escribe_log($dispositivo, $log, $comando){
$Fichero_Log = "C:\Modificacion_routers.log"
$texto = $dispositivo
    $texto >> $Fichero_Log
    $texto = $log
    $texto >> $Fichero_Log
    $texto = $comando
    $texto >> $Fichero_Log
}

##PROGRAMA PRINCIPAL##
Import-Module SSH-Sessions

$ficheroIPS = "C:\ipsdispositivos.txt"
$ficheroComandos = "c:\comandos.txt"

$dispositivos = Get-Content $ficheroIPS
$comandos = Get-Content $ficheroComandos

foreach ($dispositivo in $dispositivos) {
    New-SshSession -ComputerName $dispositivo -Username USUARIO -password PASSWORD
    foreach ($comando in $comandos) {
        $SshResults = Invoke-SshCommand -ComputerName $dispositivo -Command $comando
        escribe_log $dispositivo $SshResults $comando
        Start-Sleep -s 1
    }
    $comandos = Get-Content $ficheroComandos
}

Remove-sshSession -RemoveAll
可以完美地启动sh show命令,我的问题是,当我启动一个命令时,会自动断开会话,然后该命令无法启动conf t以进入配置模式,然后启动配置命令

您知道这个库是否可以配置路由器吗? 如果不可能,, 他们知道我使用脚本配置路由器的任何替代方案吗

已解决:

使用POWERSHELL更改SSH路由器/交换机的功能 }

有三个变量可以初始化$commands、$ssh、$devices

    #Example of file commands.txt...
    #sh conf
    #conf t
    #int f0/1
    #description Modify via powershell
    #exit
    #exit
    #wr
    #...
    $fileCommands= ".\commands.txt"
    $commands= Get-Content $fileCommands
    #Example of file devices.csv...
    #10.10.10.10;SWITCH01
    #10.10.10.11;SWITCH02
    #10.10.10.12;SWITCH03
    #...
    $devices = Import-Csv -path ".\devices.csv" -header 'ip','hostname' -delimiter ';'
    $port = 22
    $ssh = new-object Renci.SshNet.SshClient($devices[0].ip, $port, $user, $password)
    Try{
            $ssh.Connect()
            Start-Sleep -s 1
            set-SSH $commands $ssh
    }catch{
    }
    #Example of file commands.txt...
    #sh conf
    #conf t
    #int f0/1
    #description Modify via powershell
    #exit
    #exit
    #wr
    #...
    $fileCommands= ".\commands.txt"
    $commands= Get-Content $fileCommands
    #Example of file devices.csv...
    #10.10.10.10;SWITCH01
    #10.10.10.11;SWITCH02
    #10.10.10.12;SWITCH03
    #...
    $devices = Import-Csv -path ".\devices.csv" -header 'ip','hostname' -delimiter ';'
    $port = 22
    $ssh = new-object Renci.SshNet.SshClient($devices[0].ip, $port, $user, $password)
    Try{
            $ssh.Connect()
            Start-Sleep -s 1
            set-SSH $commands $ssh
    }catch{
    }