So to get started, let's look at how we
execute commands on remote computers.
Well, first off, there are some core
system requirements for utilizing what's
referred to as PowerShell remoting. The
first one is PowerShell version 3 or
higher. Luckily, we're using PowerShell 7,
so we'll be utilizing the right version.
Then, the Microsoft.NET Framework 4.0 or
higher, which for Windows 10 is perfectly
fine, it will be at least 4.7 or higher.
Then, of course, Windows Remote Management
3.0. So three core system requirements for
any type of PowerShell remoting. The
second thing we need is the correct user
permissions. So in order for this to work,
you'll need to have an administrator
credential in order to operate the
PowerShell remotely. You'll need to have
your account or the account that you use
be part of the administrators group on
both the local and those remote machines,
or at least be able to provide credentials
when you get prompted, or at least provide
them in the commands. Now you can always
see the types of commands that can be
utilized for remoting by executing a
simple command. So what we're looking for
here is we're going to use the
Get‑Command, and then we're going to look
inside the parameter keys for something
that says ComputerName. This will display
a list of the commands that will allow you
to pass a computer name. Not every
PowerShell command that you'll ever want
to utilize can be used necessarily with a
computer name parameter. Now, does that
mean it can't be used remotely? No, it
just means that you, when you initiate the
connection, you can't use that command to
target a computer, but you can bundle it
as part of a job. So the most common way
that we would connect to remote service is
by using what's called an interactive
PowerShell session to create a remote
interactive PowerShell session, we're
going to use Enter‑PSSession, and then you
can pass the computer name for this one.
You can also do New‑PSSession and do a
similar thing, but Enter will actually
connect you in and then allow you to see
that response back. We could also then
exit those PS sessions, and that's
important, because when you create the
sessions remotely, you'll need to clear
those sessions back down. We also have the
ability using the NewPSSession to create
what's referred to as a persistent,
non‑interactive PowerShell. Now, what that
means is that that allows me to pass that
session to an Invoke‑Command request using
the session property. It does not return
effectively the command prompt back to me,
it just creates a session where I can push
things into it. So if we had that
persistent kind of non‑interactive
PowerShell, we could then say
Invoke‑Command, use this session, and then
our script block can be any kind of command that we wish to utilize.