SSH Using PowerShell for Multiple Linux, Mac OS

(Last Updated On: October 3, 2016)

SSH using PowerShell is a quiet old topic, but when coming to real-time implementation, there would be few challenges in making the script. SharpSSH a Dot NET library used to connect SSH session via PowerShell and it works excellent for multiple hosts (Linux or Mac).

Steps to setup SSH using PowerShell

Download customized SSH Script contains .dll files and two .ps1 script files for executing SSH in PowerShell.

SSH using Powershell

 SSH using PowerShell

connect-ssh

 

Considerations before execution 

  1.  Make sure DNS resolution for the mentioned hosts in linux_hosts.txt are available. If DNS is not present make a host entry in the hosts file
  2. Script will not execute IP’s in linux_hosts.txt file

SSH using PowerShell

hosts-file-entry

Execution flow

  •  The Invoke-SSH.ps1 file which gets the username and password and stores it in a variable which is passed using for each enumerator to connectssh.ps1 and executes the required Linux or Mac OS commands.
  • connectssh.ps1 establishes SSH connection with the help of .dll files and retrieves the constant output in a PowerShell array variable.

invoke-ssh

SSH Using PowerShell

Video explaining SSH for Multiple hosts using PowerShell

Note: PowerShell 6.0 alpha version supports Linux and Mac operating systems, Expecting SSH or Similar remote execution support in the upcoming versions of PowerShell.