- [Instructor] In the last video,
I said that PowerShell is possibly
the single most useful tool for managing
and administering Windows servers.
One of the features that makes that true
is PowerShell remoting.
Here we sit at a Windows 10 Enterprise workstation
that is joined to an active directory domain.
The servers in this domain are both running
Windows server 2019 and we're going to take a look
at how to use PowerShell to remotely manage those servers.
Because being able to manage the machine where you sit
is one thing but that's a lot of unnecessary running around
if you have to go to the console of every single machine
that you need to administer.
Remoting is how you can manage or administer
another server or better yet all of the other servers
without leaving your workstation.
Remoting takes on two different forms.
Let me show you the first one.
Here in PowerShell, I can start a new session
where I'm actually remote controlling PowerShell
on the domain controller.
Let me show you what I mean.
There's a command to take a look
at the active directory users
on your active directory domain, it's Get-ADUser.
There's a required parameter of filter
and if I just filter star, then that's the cmdlet
that will pull a list of all of the users
in my active directory domain.
If I run that command, I'm on a workstation
that doesn't have any active directory tools installed
so I get an error saying that that command
is not available to me, that's not recognized.
Well, let's go ahead and start a session
with our domain controller.
If I type New-PSSession,
I can specify the computer
that I want to remotely connect to.
So let's say computer name is dc01.
And if I was logged into someone
that didn't have access to dc01,
I could add another credential parameter
but I'm logged in as CWhite
which is one of our administrative team
so I'm going to go ahead and just run that.
And that's going to create a session.
I haven't entered the session but the session is there.
I now have a session with the ID of one,
to the computer name dc01,
it's available, it's opened, it's ready for me to use.
So now I can run one other PowerShell cmdlet,
Enter-PSSession,
and if you're new to PowerShell,
you may have noticed and wondered why I capitalize
things the way I do.
This is called Pascal case and it's the default
and the best practice in PowerShell.
It's not necessarily required
but it helps to diagnose problems
when an expression doesn't do
what you thought it was supposed to.
You capitalize the beginning of each word
even as you have to run those words together.
So if I want to enter PSSession,
I can specify the parameter of ID
and put in the number one because that's the ID number
of the session that we created.
So when I go ahead and hit Enter,
it looks like I left out a space between ID and one,
it thinks one is part of the parameter name
and that's not recognized.
So let's up arrow and just fix that.
Enter-PSSession with the ID of one
and then I'll go ahead and hit Enter on that.
And here you can see the new prompt
has dc01 in square brackets at the beginning of the prompt.
That means I'm actually operating on that remote machine.
Let me clear the screen again to bring this to the top
and while remoted into the domain controller,
I can run Get-ADUser one more time with the filter
of star and this is a domain
that was created just for this lab.
So there aren't very many users to get
but we can see that it did go ahead
and pulled the entire list.
Once I'm done with this session, I can just type exit
and you'll see that my prompt returned to as it was before.
I'm no longer remoting the domain controller.
If I clear the screen one more time
and try my Get User cmdlet, once again,
I'm going to be told that the cmdlet is not recognized.
Now there are other times that you might want
to just run a command on multiple servers at the same time
rather than remoting into one specific server.
I can do that using another expression, Invoke-Command
will allow me to specify a script block.
And then inside curly braces,
I can put an entire function or script,
or several PowerShell cmdlets that all want to be run.
Let me use a simple one.
Let's just say Get-Process.
That will pull a list of processes running on a server
and then I can add a list of computer names
and I will put them in parenthesis.
I'm going to put each computer name in quotation marks
and separate them using commas.
So I can say dc01,
close the quotation marks,
and let's go ahead and put server three in the list as well.
Now if I go ahead and run this cmdlet,
it will reach out to both of these machines
and it will pull all of the running processes
on both server three and if I scroll back up, dc01.
Now that pulled a list of processes from these two servers.
But I could just as easily pull the same information
from every server in the domain or maybe from every laptop
in one active directory container.
The list of computers can be as long as you need.
It could even be an expression
that searches for computer names in active directory.
By default, PowerShell will run them 32 computers at a time
to manage processor time and memory usage
but you can retrieve information from a lot more than that.
In addition to having commands for every facet
of a Windows workstation or server,
anything PowerShell can do locally,
it can also do remotely on more than one machine at a time.
That's one of the reasons that I stand by my statement
that PowerShell is probably the most useful tool
you can have in administering a Windows network.