How To Use PowerShell Remoting Over Secure Shell (SSH)

PowerShell Remoting is known for using the WinRM protocol but as of PowerShell Core v6, we now have the ability to use SSH as well. In this video, Ethan shows us how to use the SSHTransport parameter on the Invoke-Command cmdlet to seamlessly execute commands just as if we were using WinRM.

In this video I am going to demonstrate how to use powershell remoting over SSH. There are a couple of prerequisites to keep in mind. First, you must have powershell core version 6 dot 0 or higher installed on both the host and client machines. Second, you will also need to have SSH installed on both the client and host machines for windows, you will need to install open SSH let's get started. Use the enter PS session commandlet to create an interactive session, you specify the target machine with the host name parameter and provide the username with the username parameter. You also need to add the SSH transport switch to force the connection over SSH. If you do not enter the SSH transport switch powershell would default to win RM for connection negotiation and data transport after you enter the command you will be prompted for your password after successfully in in your password you will notice that the prompt changes by adding the user and remote machine name as well as the current working directory changes to the session location on the remote machine. Any commands entered here will be executed on the remote machine to exit the session. We will need to type exit PS session. When scripting you can use the new PS session. Commandlet to open a persistent remote session, let's do that now. You will use the get PS session. Commandlet to view a list of active sessions where multiple sessions may be created. To terminate a remote session, you will use the remove PS session commandlet and then provide the ID of the session, you would like to terminate. He noticed there are no sessions listed. If you are simply wanted to execute a command via remote session, you can use the invoke command commandlet. Let's execute this remotely. In our password. After entering your password you will see that that command executed remotely. If we execute this command lcoally. We will see that the windows. OS versions are different. Thank you for watching and have a great day.