Accessing Remote Computers
There are really two scenarios for accessing a remote computer. The difference between those scenarios primarily
lies in the answer to one question: Can WinRM identify and authenticate the remote machine?
Obviously, the remote machine needs to know who you are, because it will be executing commands on your behalf.
But you need to know who it is, as well. This mutual authentication – e.g., you authenticate each other – is an
important security step. It means that when you type SERVER2, you’re really connecting to the real SERVER2, and
not some machine pretending to be SERVER2. Lots of folks have posted blog articles on how to disable the various
authentication checks. Doing so makes Remoting “just work” and gets rid of pesky error messages – but also shuts
off security checks and makes it possible for someone to “hijack” or “spoof” your connection and potentially capture
sensitive information – like your credentials.
Caution Keep in mind that Remoting involves delegating a credential to the remote computer. You’re doing
more than just sending a username and password (which doesn’t actually happen all of the time): you’re
giving the remote machine the ability to execute tasks as if you were standing there executing them yourself.
An imposter could do a lot of damage with that power. That is why Remoting focuses on mutual
authentication – so that imposters can’t happen.
In the easiest Remoting scenarios, you’re connecting to a machine that’s in the same AD domain as yourself, and
you’re connecting by using its real computer name, as registered with AD. AD handles the mutual authentication and
everything works. Things get harder if you need to:
•
Connect to a machine in another domain
•
Connect to machine that isn’t in a domain at all
•
Connect via a DNS alias, or via an IP address, rather than via the machine’s actual computer name as
registered with AD
In these cases, AD can’t do mutual authentication, so you have to do it yourself. You have two choices:
•
Set up the remote machine to accept HTTPS (rather than HTTP) connections, and equip it with an SSL
certificate. The SSL certificate must be issued by a Certification Authority (CA) that your machine trusts;
this enables the SSL certificate to provide the mutual authentication WinRM is after.
•
Add the remote machine’s name (whatever you’re specifying, be it a real computer name, an IP address, or a
CNAME alias) to your local computer’s WinRM TrustedHosts list. Note that this basically disables mutual
authentication: You’re allowing WinRM to connect to that one identifier (name, IP address, or whatever)
without mutual authentication. This opens the possibility for a machine to pretend to be the one you want, so
use due caution.
In both cases, you also have to specify a –Credential parameter to your Remoting command, even if you’re just
specifying the same credential that you’re using to run PowerShell. We’ll cover both cases in the next two sections.
Note Throughout this guide, we’ll use “Remoting command” to generically refer to any command that
involves setting up a Remoting connection. Those include (but are not limited to) New-PSSession, Enter-
PSSession, Invoke-Command, and so on.
Setting up an HTTPS Listener
This is one of the more complex things you can do with Remoting, and will involve running a lot of external
utilities. Sorry – that’s just the way it’s done! Right now there doesn’t seem to be an easy way to do this entirely
from within PowerShell, at least not that we’ve found. Some things, as you’ll see, could be done through
PowerShell, but are more easily done elsewhere – so that’s what I’ve done.
Your first step is to identify the host name that people will use to access your server. This is very, very important,
and it isn’t necessarily the same as the server’s actual computer name. For example, folks accessing
Secrets of PowerShell Remoting
17
http://PowerShellBooks.com • http://PowerShell.org