So now that we've installed PowerShell, let's talk about PowerShell
remoting. Now, PowerShell remoting supports Windows Management
Instrumentation, or what's called WMI, WS‑Management, which is called
WSMan, and then, of course, Secure Shell Protocol, SSH. For Powershell
7 and higher, it supports Remote Procedure Call, RPC, but it's only
supported on Windows.
Now when we talk about PowerShell remoting over SSH,
you need to be using PowerShell 6 or higher. You need to
install both the SSH client and the server.
If you're using Windows, we can simply use OpenSSH, and you can install
PowerShell directly from GitHub, which means we have the latest version, so
there are some dependencies here and prerequisites. Now,
once we have all this done,
if we wish to configure PowerShell remoting over SSH, then we first need to
install the SSH service. And to do this, for example,
in Linux, we're going to use the sudo apt install and install the
openssh‑client and server. We'll then modify the SSH configuration to
allow password authentication and public key authentication, and then
we'll specify values for PowerShell. And then once we've done that,
we'll restart using the systemctl command to restart that SSH service.
And then to connect, we can then, if we're going from Linux to Linux,
for example,
we could use New‑PSSession, the HostName, the UserName, and then once we've
connected that session, we can enter into the PowerShell session. Now,
PowerShell remoting, if we're using WSMan, enables a WinRM remote endpoint for
the connection. Then, of course, you can either use Enable‑PSRemoting, which is
a standard command built in to enable that on the Windows devices, or you can
download what's called the Install‑PowerShellRemoting.ps1 script that will do
the same configuration.
Once we've done that,
then you can connect using standard remoting PowerShell commands.
So you do need to go through this configuration process first to enable
PowerShell remoting; otherwise, your commands will fail. Now, to do this, if
we wish to enable this using the standard command, we would use
Enable‑PSRemoting and then some various parameters.
I'm using ‑Force and ‑SkipNetworkProfileCheck. If we wanted to
use the PowerShell script that's available,
we can just execute Install‑PowerShellRemoting.ps1.
Obviously, make sure we download that script first. And then to
connect, doesn't matter which one of those we used, the connection is
still the same, so we can say New‑PSSession,
connect to the HostName, and once we have that connection, we
can enter into that PowerShell session.