Common Commands Part 2

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
1 hour 43 minutes
Difficulty
Intermediate
CEU/CPE
2
Video Transcription
00:00
Hello, everyone. I'm instructor Gerry Roberts, and this is power Shell scripting
00:05
in this video, we're gonna talk more about some common commence. Specifically, commands that have to do with service is so we're gonna talk about get service, stop service starts service, suspends service, resume service and restart service.
00:22
Get service is a very useful commanded actually get to a list of service is it shows both stopped and currently running service is
00:31
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 issue or something just is not, begin the 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.
00:51
Now you can find a service specifically by using the dash name parameter.
00:57
So if you know the actual name of the service you want to look at just to get dash service space,
01:03
dash name space in the name of the service,
01:06
you can also filter. The service is using the wear object command. If you guys remember that from a previous video when we're talking about piping. We talked about where object.
01:18
Now this command will allow us to do a couple different things. One of the most useful probably is doing the wear object property status Equal Stop.
01:27
When we're looking for a specific service and we want to see if it stopped or not, we could look by name
01:34
or if we want to see what's actually running or not running, we can do our wear. Our object to see. OK, this is a lesser stopped things or this is a list of running things. So the way you would do that is get service space pipe space where dash object space dash property
01:53
status
01:56
status being stopped running all that good stuff space dash equal space stopped. Now you'll notice that the actual value here for the dash e que parameter
02:09
is going to be in quote
02:14
now. You could also do equal sign here, but in some versions of power shelf deprecate ID and does not work properly. So you're gonna wanna do dash e Q
02:23
for equal
02:28
Now. Another item with get service and all the other service commands is dash named vs dash display Ning. Now a lot of times, you could look things up by names. You can also use the display name. So Service's have those two names that you can look for
02:45
the regular name and the display name.
02:47
Dash Name is the usual name for the service, and display name is the despite being given to the service. So if you look at this screen shot here, you'll see that there's a list of names and a list of display names. So if you use get dash service,
03:05
you can actually go through the list and find what your actual name and display name ISS.
03:10
Now. One thing to note display name is usually a little bit longer.
03:15
Then your name. It has more information in it and can kind of tell you more about what the actual service ISS. So sometimes we don't quite know what it is by name, but if we look at display name, we can get some more information and kind of figure it out.
03:30
Another thing you can do with get service is get required. Independent service is now. Sometimes our service is actually depend on each other in order to run properly.
03:40
So if we need to find out what those service's are. When we're looking at a service, we can do that.
03:50
So if you want to find out which service is a service needs in order to run, so these air the service is that have to be running for our current service that we want to look at to run. You use the dash. Required service is switch parameter at the end of your command, and it can help you find
04:06
that service so that command might look something like it.
04:10
Dash service space Dash name. But the name in space and then dash required service is
04:17
now to find out which service's require the current service we will look at to run,
04:24
so those air service is that are dependent on our service. You use the dash Dependent service's switch parameter at the end, just like you would do with the dash. Required Service is
04:34
another useful command to stop service.
04:38
Now, if we run into an issue where service is taking up, a lot of resource is or it's crashing or having issues we could do stop service. Once the service has stopped, you have to start it again in order for to run. So what's it stopped? It's not gonna do it.
04:55
So
04:56
usually when you look this up, you look for it by name. So, for example, you might do
05:01
stop dash service space. Dash name space Spolar. That's for the printer Spolar.
05:09
You can also use display name here if you know what the display name ISS is, just a little easier to use. Dash name. Because Dash name is a shorter version,
05:18
start service starts service will actually start something. That's what stopped you. Remember when I said Stop Service's have to be started again in order to run so you would you start service to do that works the same way as any other. Service command typically requires the dash name,
05:36
or in some cases, you could do display in it so it would be similar. And maybe start dash service space. Dash name
05:46
space, the service name. In this case, it's Spolar because we stopped the Spolar in the previous slide.
05:53
Suspend service.
05:55
Now, if you're used to working a task manager, you're probably used to being up to right click and pause. Certain service is this is pretty much the same thing. But it said a pause a use of work suspend so suspend dash service pauses The service.
06:11
Now, one thing to note is not all service is allow you to suspend them. So when you try to do the suspend sash service and use the name, it'll give you a big old wall red tacks and say Hey, you can't do that now The syntax for this is pretty much similar to all the other commands.
06:28
You use the suspend, our service space and then do dash name. You can also do dash display name with this one. And in this case we did, schooler, cause we've been using that already. So we just suspend dash service space Dash name space Spolar
06:46
Yeah, resume service. Won't you suspend a service? It's just gonna sit there, not do anything until you actually started up again. In order to start it up again, you have to resume it so you would do resume dash service space
07:00
Fash name and then the service name in order to get it to run Same syntax pretty much is all the other service commands typically uses dash name, But this one is well, you can do dash despite knowing it's on our example. Here we did Resume dash service. Dash name Spolar
07:17
Restarting of service. Now, sometimes you don't want to stop and start a service. Instead, you just want to restart it. Um, this command actually allows you to do that. This is very useful. If a service is hanging or having issues or throwing airs
07:35
uses the same sin taxes other service commands typically uses dash, name, toe, locate the service. No. One of the more common ones you run into is a preacher, Spolar.
07:46
That sometimes has to be restarted because things get caught in the printer cache, and then the printer just doesn't work. So you have to restart the Spolar to get it going. There's some other ones like D. N s and stuff like that on servers that you might have to restart. A swell. Very simple to Dio is just restart that service space
08:05
dash name
08:07
space and then the name here. We just did spook her because that's what we've been using.
08:13
It is now time for us to go ahead and take a look at what that actually looks like.
08:18
All right, now that we're in power shell, we can go ahead and start to take a look at what those commands look like. The 1st 1 is get serviced. We take it,
08:26
dash service
08:28
and your nose. You get a huge list of different service is you'll see a status
08:35
running stopped. You'll see the name
08:39
and then you'll see the spine. And if you screw all the way up, you can see
08:46
the actual titles here. So here's your stash is going to stop your running
08:50
the name
08:52
and the despite ing
08:54
now say we want to get a specific service by a name.
08:58
We could look for that name.
09:03
You look through our list. It is alphabetical, so you should be able to find things by alphabet
09:11
and say, We want to do the Prince Bowler. We're just gonna take Spolar
09:18
and you do get their servants space Dash name
09:28
and then it's schooler
09:33
and you'll see that you get the information there. You can also do it by display name
09:37
so I can go back and do this lane despite in this
09:48
print schooler. But watch what happens
09:52
when I do that.
09:54
Now that happens if there is a space in the name. If there's a space in the name
10:03
you're gonna have to do quotes.
10:09
And you see, it works perfectly fine when you do that.
10:13
The other thing is filtering using the wear object so we can do get service, pipe, the wear object.
10:26
And in this case, we want to look at the property
10:30
of status, which is that first column.
10:33
And then we're going to do equals because we were It's equal a specific thing, and we're gonna do stop
10:41
you notice we get a huge list of different things and you can see these are all the different stopped. Service is.
10:50
You could also do that for running. You could also do the property of name and display name and do equals.
10:58
However,
10:58
there's already a dash displayed a and a dash name,
11:03
as you can see, so you don't necessarily have to do the where object. In that case,
11:13
the next thing is name and displaying it.
11:16
As you see here,
11:18
you could do display name any to name
11:22
now again, if you're doing a service and it has a space in it,
11:28
you want to use a quote.
11:33
In addition to being able to use, get service to find out information about all service is in specific service is you could also get required. Independent service is
11:43
so say, for example, we wanted to find out
11:48
what service is
11:50
schooler needed to run.
11:52
So schoolers running and we need to know what it requires store. So we do get service.
12:00
The review. New schooler That's the printer, schooler
12:05
and required service is
12:09
and you get a list of service is that are required in order for schooler to run. So far, our PC or remote procedure calling our http service's are not running.
12:22
Guess what schoolers not gonna run either because it requires says we can also find out what service's are dependent on schooler, meaning which service is
12:33
actually need to have smaller running in or to run.
12:39
So we do Dependent
12:43
Service's.
12:46
And, of course, spelling does count.
12:50
All right. You will knows, too, though, that the capitalization doesn't matter here. This particular module doesn't really care about capitalization, but if I do Dependent Service's, we see that the fax has to have the printer schooler running in order to work.
13:05
That kind of makes sense, right, because the facts and the printer usually do a lot of stuff together.
13:15
The next thing we want to look at is stopping. Starting service is so stop Service's stops a service completely. So if we do stop
13:24
service
13:24
and we d'oh
13:26
spear,
13:30
we don't get anything that comes up to tell us it stopped. But if we could get service,
13:37
you knew that schooler.
13:41
We'll see that the schooler is stopped. Yeah, it's going to stay in that state unless you tell it to do something different. So we have to do start service
13:52
in order to get it running again.
13:56
Yeah,
13:58
you go back.
14:01
And now it's running again.
14:07
In addition is starting and stopping service is we can also cause and resume them now. Power show uses a little bit different language that eat Posy, you suspend. So use this phone service
14:22
and then you do me. Oh, we got red text. Remember what I was talking? The power point about how some service is. You can't pause and you can't Arzu. So, for example, here are schooler. You can't
14:39
pause and you'll get that error and you'll see that it says it cannot be suspended due to the air.
14:48
Cannot pause schooler service on computer.
14:54
That means Hey, you can't use a pause for that particular service.
14:58
Now, if you had suspended the service,
15:01
it would show up is suspended. And then you could do resume
15:05
service
15:07
leave and then the name you noticed again. They're here again because we use Spolar. Can't positive resume Spolar. Now, one thing you can do with Schooler
15:20
is you can restart it so you could restart service Dash name cooler.
15:30
And you don't notice anything. Something happens. But your task manager, you don't really notice anything. It just kind of starts up again after it stops. So if we get schooler, we'll see that it is now running the restart service. Usually fairly quick, depending on the service.
15:50
Okay, Now that we've had a chance to do our demo,
15:54
it is post assessment time.
15:58
So for this post assessment, we want to know if you suspend a service. How would you start it up again? But 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.
16:22
All right, The answer is D resume service.
16:26
What's a service is suspended. Your girl want to resume it to start running again?
16:33
That's it for this video we talked about Working with service is
Up Next