So let's get into our environment,
and we'll look at how we can enable PowerShell remoting using WS‑MAN.
We'll enable remoting within Windows,
and then we'll test that connection to the Windows server using
that PowerShell remoting that we've just enabled.
Now in order for us to remotely connect to another machine,
we do need to enable PSRemoting.
Now to do this, there's a couple of different approaches,
and we've talked about some of these.
So our first one here is we're going to execute
WSManQuickConfig. And you can press Enter here,
and it will display what it's going to do.
So the first thing it will do is check if the service is running,
start the service if it needs to, create the listeners,
etc.
And what we mean by the service is if I just go to
Services here and launch this,
I'm going to scroll all the way down towards the bottom,
and you'll see we have remote PowerShell here,
which is currently set to Automatic because I had it already configured,
but I'm stopping that so you can see that kicking back in when we do it.
Now on your machine, it may not be running at all.
But this is a Windows Server 2022, and of course,
I want to connect to it from another machine.
So we, first off,
need to understand what it looks like when we try to connect to
something that isn't enabled for Remote Management.
So let's go back to our Windows 10 machine.
So here's the Windows 10 Machine.
Now here's the Windows 10 machine.
From here, we can initiate a connection to the other machine.
So maybe what we can do is use the Invoke‑Command,
and you can see I'm going to call the Get‑Service command as before,
and it's going to be to the same IP address,
which is the Windows Server 2022.
I'm going to press Enter here. This is now going to go and try and
connect. Now previously, when I had this enabled,
it would just go and retrieve all the services. But now, it won't do anything
because that Remote Management service isn't actually executing and running in
the background. And all the components such as the firewall rules and whether
it's configured for Kerberos authentication,
whether the listener is there, none of it works.
And so this is the message that you get back. It's going
to say you're not able to connect.
So we'll then go back to the Windows machine, and we'll configure that
service. We'll just use the WSManQuickConfig, or we'll use a different
approach to enable it so we can then connect. So we're back on the Windows
Server. So let's execute that Set‑WSManQuickConfig.
This is one approach. And we simply can just say yes. This will go
through and configure all of the pieces that are there. It will say
WinRM has been updated. The service has started.
So let's go to Services here, and we'll scroll all the way back
down again to the services, and you'll see the Remote
Management service is now running. Now,
what does that look like when we connect to it?
Well let's go back to our Windows 10 machine. So now we're back
here. Let's just clear that. And we'll issue the same command,
and now it returns the values.
So simple as the service not running can actually cause it to not
execute along with the firewall rules and everything else.
So let's just clear this.
Now let's go back and we'll disable it again, and then we'll
look at the second approach to enabling this.
So back on here, so let me just go here and say stop so we know that
service doesn't run. We'll minimize that because we'll come back to it
later. And then we'll just clear this here.
The other approach is to use what's called Enable‑PSRemoting as an option,
and then we can do ‑Force to force the enablement of that.
I can press Enter here. It will say yes. It's going to go ahead‑‑‑ Notice the
messages that come back are really similar to the message using the
Set‑WSManQuickConfig. And so now it says it's been updated. So let's go back
to here, and we'll just refresh. And sure enough,
it says running the service. So it puts it all back. Now if
you've never run this in the first place,
there's a few more bits and pieces that take place,
not just the Windows Remote Management service gets started. But of course,
it will configure all the components that are required,
such as the firewall rules and everything else to make that work.
Now that we have that connected,
now, of course, we can issue commands from the Windows 10 device to the
Windows server. And it would be exactly the same no matter what type of
Windows server we were trying to connect to.
So let's go back to our Windows 10 device.
So this means now that it's enabled on that Windows server that
we can execute any type of command that would allow us to pass
a computer name as part of that.
So we can go back to our Invoke‑Command option.
Same server. I could change that to be Get‑Process,
press Enter, and it's going to go ahead and connect and
return the processes from that remote machine.
It would also accept the CIM instance commands, also the WMI commands,
or any other type of PowerShell cmdlet, especially if we were entering
or connecting to a PowerShell session.
So that's as simple as it is to enable Windows Remote Management. Now,
it can be a little bit more complicated if there's
different types of authentication,
if the accounts that you're using are different, and sometimes you might
need to modify what's called the trusted host list,
which allows you to add trusted machine names and IP addresses so the
connection can be enabled. But for at least in my environment,
everything is all fairly straightforward, all the machines are separate, and
you can communicate over IP address. If you're in a domain,
then, of course, that would be a little bit different because you'll
be using Kerberos and some type of authentication,
and then you will need to potentially use the trusted
host list to kind of add those in.
But we can talk about that a little bit later.