Powershell Script to Execute SSH Commands

Powershell based script which can connect SSH based devices (network, Linux/Unix based devices) and execute any set of commands.

It will then take the output and save in multiple txt files.

Testing scenario

  • Backup of 20 Network Device Configuration
    • Took less than 10 Seconds per device
    • Output was saved in multiple text files (each named as device’s hostname)
    • Created separate list of failed devices
    • No special configuration required on device

Link to the Powershell Script

4 thoughts on “Powershell Script to Execute SSH Commands

  1. But can you please tell me how to send enable password also as my router and switches have enable password as well and not able to execute anything without entering another enable password ..

  2. Hi … your script looks like justthe thing I need and I am trying to run it but it keeps throwing out the following – if it makes a difference this is Windows Server 2012r2 but running script with full admin rights:

    Import-Module : The specified module ‘SSH-Sessions’ was not loaded because no valid module file was found in any
    module directory.
    At C:\script\Run-SSHCommand.ps1:24 char:1
    + Import-Module SSH-Sessions
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (SSH-Sessions:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    new-object : Cannot find type [Renci.SshNet.SshClient]: verify that the assembly containing this type is loaded.
    At C:\script\Run-SSHCommand.ps1:77 char:8
    + $ssh = new-object Renci.SshNet.SshClient($device.ip, $port, $user, $password)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

    Any thoughts on fixing it please?

Leave a Reply

Your email address will not be published. Required fields are marked *