Posh-SSH is a PowerShell module for Windows 10. The module enables you to establish SSH connections to remote computers. As a prerequisite, Windows Management Framework 5 has to be installed. In this article I am going to show step-by-step how to install Posh-SSH and establish a remote connection to a computer running Linux.
In Windows, SSH connections are somewhat unusual, because PowerShell has it’s own feature, but SSH is indispensable for accessing non-Windows devices, like switches, routers and last but not least Linux machines.
Run Find-Module to look for the new PowerShell Module Posh-SSH. If you can’t find it, install .NET Framework 5.0 from this source: https://www.microsoft.com/en-us/download/details.aspx?id=50395
Install it by running a simple One-Liner.
Find-Module Posh-SSH | Install-Module
Once completed, feel free to explore the new Posh-SSH commands. For the next step, we need only two of them.
Get-Command -Module Posh-SSH
Running SSH on Windows PowerShell
Now connect to a remote host using New-SSHSession.
New-SSHSession -ComputerName Server01
Run Get-SSHSession to show all current connections. My connection has Session Id 0. We need this session ID in the next step.
Remote commands are entered by running Invoke-SSHCommand and the Session Id.
Invoke-SSHCommand -SessionId 0 -Command cut -d: -f1 /etc/passwd
If you like the Windows PowerShell built-in feature “PowerShell Remoting” more, then have a look at my article: PowerShell Remoting: How to connect to Remote Hosts in a Domain- and in a Non-Domain Environment (Trusted Hosts)