I wrote a module for dealing with SSH sessions from PowerShell, based on the SSH.NET library found on CodePlex. It has New-SshSession to create connections (multiple targets using different credentials is supported), and then you can use Invoke-SshCommand to run commands against any number of target hosts. There's even an Enter-SshSession which has a very basic, interactive shell.
Download OpenSSH for Windows and choose to install just the client during the installation. The entire installer inlcuding the server is less 3MB and the client works just fine.
I am still posting an answer to this question, because i found the accepted answer not suiting my needs at all (Only a paid solution or another that doesn't handle the terminal well).
So the obvious solution to this problem is to install cygwin. Do a minimal install if you just want ssh, but since powershell provides a basic level of compatibility with *nix shells (basic commands are still there, "/" for directories, etc), it's really possible to use cygwin stuff inside Powershell.
It creates a shortcut to a posh-git window with all the paths set correctly to use git in powershell. That automatically comes with ssh and scp binaries in the path.
I am not sure what implementation it is, but it does have a Linux like feel, i.e. it doesn't feel like it is .Net based or uses powershell commandlets.
It is picking up the private key that I have configured in $home/.ssh/ in openssh format and maybe someone can confirm. It feels like it is openssh.
To make it even better, I have integrated it into my regular powershell profile by doing the following in my $profile. That means that I don't have to use github's shortcut.
Full documentation is provided at the link above. In a script you don't really want an interactive connections, so it is two steps. 1st create the session. 2nd send commands.
The first session you create will have an index of 0.
Invoke-SSHCommand -Index 0 -Command "some command to run over ssh"
It is best practice to put the connection creation in a try catch and to validate the session exist before running a command. This makes interacting with Linux servers from inside of a powershell script work well.
Not built in of course, but since Powershell can do anything .Net can do, there is a way.
Paid solution would be /n Software's NetCmdlets.
Free solution would be using the suggestions of this blog post.
I wrote a module for dealing with SSH sessions from PowerShell, based on the SSH.NET library found on CodePlex. It has New-SshSession to create connections (multiple targets using different credentials is supported), and then you can use Invoke-SshCommand to run commands against any number of target hosts. There's even an Enter-SshSession which has a very basic, interactive shell.
The article is here.
Joakim
Download OpenSSH for Windows and choose to install just the client during the installation. The entire installer inlcuding the server is less 3MB and the client works just fine.
I am still posting an answer to this question, because i found the accepted answer not suiting my needs at all (Only a paid solution or another that doesn't handle the terminal well).
So the obvious solution to this problem is to install cygwin. Do a minimal install if you just want ssh, but since powershell provides a basic level of compatibility with *nix shells (basic commands are still there, "/" for directories, etc), it's really possible to use cygwin stuff inside Powershell.
Cygwin install here
There's an alternative (free) PowerShell SSH solution, using a newer library implementation, see vBlog >> SSH Client Using PowerShell
One way to get a very good native ssh client is to install git from GitHub (https://windows.github.com/).
It creates a shortcut to a posh-git window with all the paths set correctly to use git in powershell. That automatically comes with ssh and scp binaries in the path.
I am not sure what implementation it is, but it does have a Linux like feel, i.e. it doesn't feel like it is .Net based or uses powershell commandlets.
It is picking up the private key that I have configured in $home/.ssh/ in openssh format and maybe someone can confirm. It feels like it is openssh.
To make it even better, I have integrated it into my regular powershell profile by doing the following in my $profile. That means that I don't have to use github's shortcut.
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1") . (Resolve-Path "$env:LOCALAPPDATA\GitHub\PoshGit_*\profile.example.ps1")
I know this is very old reply, but for the sake if sharing knowledge I would like to let you know that Microsoft has added a built-in SSH client and it is now enabled by default in Windows 10’s April 2018 Update (check this https://devblogs.microsoft.com/powershell/looking-forward-microsoft-support-for-secure-shell-ssh/ and this https://www.howtogeek.com/336775/how-to-enable-and-use-windows-10s-built-in-ssh-commands/)
so you are now able to create ssh session inside your PowerShell script natively.
Enjoy!
If the target machine is a Windows box, then you can use PowerShell Remoting, instead.
It's definitely not the same as SSH. There are pros (bringing objects back over the wire!) and cons (what if the target is Linux?).
I use Git http://git-scm.com/downloads
Includes a host of other tools like SCP and such that are useful too.
Posh-SSH Is a free module from Poswershell Magazine that works for Powershell 3.0 and above.
It is available at http://www.powershellmagazine.com/2014/07/03/posh-ssh-open-source-ssh-powershell-module/
Full documentation is provided at the link above. In a script you don't really want an interactive connections, so it is two steps. 1st create the session. 2nd send commands.
The first session you create will have an index of 0.
It is best practice to put the connection creation in a try catch and to validate the session exist before running a command. This makes interacting with Linux servers from inside of a powershell script work well.