Common Commands Part 4

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 »

Difficulty
Intermediate
Video Transcription
00:00
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell. Scripting
00:06
this video, we're gonna learn some more commands. Were gonna actually look at locations more specifically, working with your current location or you're working directory. So we're gonna work with get location, set, location, and we're gonna learn about push location and pop location.
00:25
First of all, getting your current location. When you're in power Shell, you can find out what you're working Directory is by using the get dash location command. This will display the path of the Kurt Working directory for you.
00:39
If you want to set your location, you can change it by doing set dash location. Now, one thing to note that inside of power show, you can still use CD C, h, er, sl or any other commands that you normally can use in the command line. Prompt to change your location.
00:59
Now set location will actually set the location of your working directory.
01:04
And when you do it, the prompt will change to reflect the new directory. Just a CD or any of those commands. Well, when you're doing the command, you do set dash, location, space bash, path. That path specifies the directory that you're going to
01:22
if you want to display some more information about the change you can use. The dash passed through
01:29
Parameter Switch
01:30
had the end, so that way it will display more information
01:36
now passed through may also be used with some other commands. To get additional information, it's not specific to set or get location.
01:44
You can also
01:46
save your locations will recall them later. Using something called Push and Pop
01:52
Push allows you to save the current location in the stack.
01:57
Now the stack is like any other staff that you durably work with, its first in last out. So it means the last location you put in will be taken off the top of the stack when you go to pop it.
02:10
Now what Pop does
02:13
his. It takes you back to the most recently saved directory by pulling the top location off of the stack
02:23
and then bringing you there,
02:28
and now it is time for a demo so you can see what those commands look like.
02:32
So now let's take a look at some of those location commands. The 1st 1 is get location. That's pretty much just going to give us a hurt path. So get medication and you could see that currently are working directory SC Windows System 32.
02:51
Now, this might be important because some commands actually are impacted by the current working directory. So you want to make sure you're in the right place
03:01
now, the next thing you can do is set location. Now set location will allow you to set the location to a place you'd like to go. It's very similar to the way that C. D works in that. If you were to say CD too
03:23
see and then windows. You see how you change into windows and if your toe CT back on, do you see
03:32
Windows
03:35
System
03:38
32?
03:39
He would go back to System 32. Now when you do set location, it's pretty similar.
03:46
So what you do is you do set location
03:52
and then you do the path parameter, and then you do the path so it's here. Let's go ahead and do see windows like we did with CD,
04:01
and you could see that it does a very similar thing. Now, if we want to go back, we can do the same thing
04:09
and just put our system 32 path.
04:14
And there you go.
04:15
So that's setting location. Now. Another thing was set location that we talked about was the past through command. Now, you noticed when we were setting the location in these two other spots, we didn't get a confirmation. The only thing we got was that the prompt changed the directory.
04:34
So if we want some sort of confirmation and information we can use passed through
04:40
at the end and look that we get an actual path, that it shows us where it's gonna go, lastly, we want a look at saving it, recalling recent locations which are push and pop commands.
04:57
So what we're gonna do is we're gonna get our current location to see where we're at, which we know is in system 32
05:04
and then we're going to change our location by going ahead and pushing the current location onto the stack.
05:16
So we d'oh push location half,
05:26
and then we're gonna move to the local Settings folder
05:30
by doing a path and local Sanks now push works sort of like set location. But instead of just moving, what it does is it pushes your current location.
05:43
Odds the stack and then goes to the location, You tell it. So here we're gonna go ahead and push the local settings
05:54
how to where we're going to go. And then we're gonna save the system 32 in our stack.
06:02
You notice I got air. That's actually because there is no local settings in System 32
06:11
your local settings, folders, air, actually, in your users folders.
06:15
So if you put the wrong path,
06:20
it's not gonna find it, and you're gonna get an error, and it's just gonna stay on the carp. Now, we can also try maybe going to a user. So let's do actually see, do you see
06:36
if you want to see what's in a director, you can do D I r for directory,
06:41
and it will show you what's in there.
06:44
Now, if you see
06:46
we have a couple different folders here,
06:49
let's say we want to go find users. So you see,
06:55
and then users
07:00
they were in the users. Now we can see what's inside of users. We have a couple users.
07:05
No, this is where we're gonna go ahead and do some push and pop. We're gonna push the current location onto the stack
07:14
and then
07:15
we're going Thio, move to my folder
07:20
and notice Now that I'm in my folder
07:25
Now, we're also going thio
07:28
change again. So we have another location in the stack because we're going to try to build up the stack here, Do directory to see what's in
07:39
there. You can see all sorts of stuff, but we're gonna go ahead and go to the documents folder similar. Get a push location that's gonna save our Kurt item in our staff and then we're gonna path. They were gonna documents,
08:00
and now we're in a different location.
08:03
So next, let's get our location and we see where in documents.
08:11
Now work it a pop to the last location. We are thin with top location,
08:18
and you could see it there. But you could also do get location to see what we're currently act.
08:26
It's kind of cool. You can save it in the stack and then go back and you can keep going back till all you're saved
08:35
locations until you hit the end of the stack. So that's kind of useful. If you're working in multiple locations, I want to go back and forth,
08:46
but Just make sure that when you're pushing and your poppy that you remember where you're at because it's easy to get lost. But this is also an easy way to have the ability to go back and forth between different locations
09:03
instead, a set location or CD or CH ter or any of things like that.
09:09
That's it for our demo first locations. Now it's off to quiz time.
09:16
In this quiz. We want to know if you wanted to get back to the most recently saved location, the stack. Which command would you use? Would you use push location, set, location, get location or pop location? I give you a minute to figure that out. You could also pause if you want, and then we'll get the answer.
09:39
All right. The answer is D pop location. Remember, Pop location allows you to pop that last save location in the stack so you can go back to it.
09:50
This is due to the stack being file. Oh, remember, first in last out. So it's kind of like of a stack of books. So the last book you put in you can grab.
10:00
So that's it for this video. In this video, we talked about locations