SSH Using PowerShell for Multiple Linux, Mac OS

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.

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

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.

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.