>> Hello everyone. I'm instructor Jerri Roberts,
and this is PowerShell Scripting.
In this video, we're going to
talk more about some common commands,
specifically commands that have to do with services.
We're going to talk about Get-Service,
Stop-Service, Start-Service,
Suspend-Service, resume-Service, and Restart-Service.
Get-Service is a very useful command.
It actually gets you a list of services,
it shows both stopped and currently running services.
This could be very,
very useful if you're trying to
figure out what's running and what's not,
especially if you're trying to
troubleshoot an issue or something just is
not being able to
launch or it's crashing or things like that,
you can go in and just do a quick Get-Service,
find your service and see if it's actually running.
Now you can find a service
specifically by using the -name parameter.
If you know the actual name of the service you want to
look at just to Get-Service,
space, -name,
space and the name of the service.
You can also filter
the services using the Where-Object command.
If you guys remember that from
a previous video when we were talking about piping,
we talked about where object.
Now this command will allow
us to do a couple different things.
One of the most useful probably is doing the
where object property status equals stop.
When we're looking for a specific service
and we want to see if it stopped or not,
we can look by name,
or if we want to see what's
actually running or not running,
we can do our Where-Object to see, okay,
this is a list of stopped things
or this is a list of running things.
The way you would do that is
Get-Service space Pipe space
Where-Object -Property Status.
Status being stopped, running all that good stuff,
space -equal space stopped.
Now you'll notice that the actual value here for
the -eq parameter is going to be in quotes.
Now, you could also do a equal sign here,
but in some versions of PowerShell is
deprecated and does not work properly,
so you're going to want to do -eq for equal.
Now another item with Get-Service and
all the other service commands
is -Name versus -DisplayName.
Now a lot of times you can look things up by name,
you can also use the display name.
Services have those two names that you can look for,
the regular name and the display name.
-Name is the usual name for the service and
DisplayName is the display name given to the service.
If you look at this screenshot here,
you'll see that there's a list of
names and a list of display names.
If you use Get-Service,
you can actually go through the list and
find what your actual name and display name is.
Now one thing to note,
DisplayName is usually a little
bit longer than your name.
It has more information in it and can
tell you more about what the actual service is.
Sometimes we don't quite know what it is by name,
but if we look at DisplayName,
we can get some more information and figure it out.
Another thing you can do with Get-Service
is get required independent services.
Now sometimes our services actually depend
on each other in order to run properly.
If we need to find out what
those services are when we're
looking at a service, we can do that.
If you want to find out which services
a service needs in order to run,
so these are the services that have to be running
for our current service that we want to look at to run,
you use the dash required services switch
parameter at the end of your command,
and it can help you find that service.
That command might look something like Get-Service,
space -name, put the name in,
space, and then -RequiredServices.
Now to find out which services
require the current service we want to look at to run,
so those are services that are
>> dependent on our service,
>> you use the -DependentServices
switch parameter at the end,
just like you would do with a -RequiredServices.
Another useful command is Stop-Service.
Now if we run into an issue where a service is
taking up a lot of resources
or it's crashing or having issues,
we can do Stop-Service.
Once the service is stopped,
you have to start it again in order for it to run.
Once it's stopped, it's not going to do anything.
Usually when you look this up,
you look for it by name.
For example, you might do Stop-Service -Name Spooler.
That's for the printer spooler.
You can also use display name here,
if you know what the DisplayName is.
It's just a little easier to use -Name
because -Name is a shorter version.
Start-Service.
Start-Service will actually start
something that has been stopped.
Now remember when I said stop
services have to be started again in order to run,
so you would use Start-Service to do that.
Works the same way as any other service command
typically requires the -name,
or in some cases you can do DisplayName.
It'll be similar and it would be
Start-Service space -name space
the service name in this case is spooler
because we stopped the spooler in the previous slide.
Suspense-Service.
Now, if you're used to working a task manager,
you're probably used to being able to
right-click and pause certain services.
This is pretty much the same thing,
but instead of pause they use the word suspend.
Suspend-Service pauses the service.
Now one thing to note is not
all services allow you to suspend them,
so when you try to do
the Suspend-Service and use the name,
it'll give you a big old wall of
red text and say, hey, you can't do that.
Now the syntax for this is pretty
much similar to all the other commands,
you use the Suspend-Service space,
and then do -name,
you can also do -DisplayName with this one.
In this case, we did
spooler because we've been using that already,
so we just Suspend-Service -Name Spooler.
Now, Resume-Service.
Once you suspend a service,
it's just going to sit there and not do anything
until you actually start it up again.
In order to start it up again you have to resume it.
You would do Resume-Service -Name,
and then the service name in order to get it to run.
Same syntax pretty much as
all the other service commands typically uses -Name,
but this one is, well, you can do -DisplayName.
In our example here we did
>> Resume-Service -Name Spooler.
>> Restarting a service.
Now, sometimes you don't
want to stop and start a service,
instead you just want to restart it.
This command actually allows you to do that.
This is very useful for services
hanging or having issues or throwing errors.
Uses the same syntax as other service commands,
typically uses -Name to locate the service.
Now one of the more common ones you
run into is the printer spooler,
that sometimes has to be restarted
because things get caught in the printer cash,
and then the printer just doesn't work,
so you have to restart the spooler to get it going.
There's some other ones like DNS and stuff
like that on servers that you
might have to restart as well.
Very simple to do is just Restart-Service -Name,
space, and then the name
here we just did Spooler
because that's what we've been using.
It is now time for us to go ahead and
take a look at what that actually looks like.
Now that we're in PowerShell,
we can go ahead and start to
take a look at what those commands look like.
The first one is Get-Service and we type Get-Service.
[NOISE] You'll notice you get
a huge list of different services.
You'll see a status running, stopped.
You'll see the name,
and then you'll see DisplayName.
If you scroll all the way up,
you can see the actual titles here.
Here's your status, is going to be stopped or running,
the name and the DisplayName.
Now say we want to get a specific service by a name,
we could look for that name.
We would look through our list and it is alphabetical,
so you should be able to find things by alphabet.
Say we want to do the principle,
we're just going to take spooler,
and you do Get-Service -Name. [NOISE]
>> Then it's spooler.
You'll see that you get the information there.
You can also do it by display name.
I can go back and do display name.
The display name is print spooler.
But watch what happens when I do that.
Now that happens if there is a space in the name.
If there's a space in the name,
you're going to have to do quotes.
You see it works perfectly fine when you do that.
The other thing is filtering using the where object.
We can do get-service pipe the where objects.
In this case we want to look at the property of status,
which is that first column then we're going to
do equals because we want to equal to
a specific thing and we're going to do stop.
You get a huge list of different things.
You can see these are all the different stop services.
You can also do that for running.
You can also do the property of name
and display name and do equals.
However, there's already
a dash display name and a dash name, as you can see.
You don't necessarily have to do
the where object in that case.
The next thing is name and display name.
As you see here,
you can do display name and you can do name.
Now, again, if you're doing
a service and it has a space in it,
you want to use a quote.
In addition to being able to use get-service to find
out information about all services
and specific services,
you could also get required independent services.
Say for example, we wanted to find
out what services spooler needed to run.
Spooler is running and we need to
know what it requires to run.
We do get-service,
then we do name spooler,
that's the printer spooler and required services,
and you get a list of services that are
required in order to first spooler to run.
If our RPC or a remote procedure call and our HTTP
services are not running, guess what?
Spooler's are not going to run
either because it requires service.
We can also find out
what services are dependent on spooler,
meaning which services actually
need to have a spooler running in order to run.
We do dependent services.
Of course, spelling does count.
You will notice too though,
that the capitalization doesn't matter here.
This particular module doesn't
really care about capitalization.
But if I do dependent services,
we see that the facts has to have
the printer spooler running in order to work.
That makes sense because
the facts and the printer
usually do a lot of stuff together.
The next thing we want to look at in
stop and starting services.
stop-services stops a service completely.
If we do stop-service and we do spooler,
we don't get anything that
comes up to tell us it's stopped.
But if we did get service and we will look at spooler,
we'll see that the spooler is stopped.
Now, it's going to stay in
that state unless you tell it
>> to do something different.
>> We have to do start-service
in order to get it running again.
Now it's running again. In addition
to starting and stopping services,
we can also pause and resume them.
Now, PowerShell uses
a little bit different language [inaudible] suspend.
You' do suspend-service and then you do name spooler.
We got red text.
Remember when I was talking the PowerPoint about
how some services you can't pause and you can't resume.
For example, here our spooler you
can't pause and you'll get that error.
You'll see that it says it cannot
be suspended due to the error.
Cannot pause spooler service on computer.
That means hey, you can't
use pause for that particular service.
Now if you had suspended the service,
it will show up as suspended and then you could do
resume-service name, and then the name.
Now notice you get an error
here again because we use spooler,
you can't positive resume spooler.
Now one thing you can do with
spooler is you can restart it.
You can do restart-service-name spooler,
and you don't notice anything.
Same thing happens in task manager,
you don't really notice anything.
It just starts up again after it stops.
If we get spooler,
we'll see that it is now running.
The restart service usually is
fairly quick depending on the service.
Now that we've had a chance to do our demo,
it is post assessment time.
For this post assessment,
we want to know if you suspended a service,
how would you start it up again?
Would you do a restart-service,
would you do a start-service,
would you do a suspend-service,
or would you do a resume-service?
I'll give you a few moments.
You can pause if you want,
and then we'll get the answer.
The answer is D, resume-service.
Once a service is suspended,
you're going to want to resume
it to start it running again.
That's it for this video,
we talked about working with services.