1 hour 43 minutes
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell. Scripting
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.
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.
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.
Now set location will actually set the location of your working directory.
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
if you want to display some more information about the change you can use. The dash passed through
had the end, so that way it will display more information
now passed through may also be used with some other commands. To get additional information, it's not specific to set or get location.
You can also
save your locations will recall them later. Using something called Push and Pop
Push allows you to save the current location in the stack.
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.
Now what Pop does
his. It takes you back to the most recently saved directory by pulling the top location off of the stack
and then bringing you there,
and now it is time for a demo so you can see what those commands look like.
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.
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
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
see and then windows. You see how you change into windows and if your toe CT back on, do you see
He would go back to System 32. Now when you do set location, it's pretty similar.
So what you do is you do set location
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,
and you could see that it does a very similar thing. Now, if we want to go back, we can do the same thing
and just put our system 32 path.
And there you go.
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.
So if we want some sort of confirmation and information we can use passed through
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.
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
and then we're going to change our location by going ahead and pushing the current location onto the stack.
So we d'oh push location half,
and then we're gonna move to the local Settings folder
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.
Odds the stack and then goes to the location, You tell it. So here we're gonna go ahead and push the local settings
how to where we're going to go. And then we're gonna save the system 32 in our stack.
You notice I got air. That's actually because there is no local settings in System 32
your local settings, folders, air, actually, in your users folders.
So if you put the wrong path,
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
if you want to see what's in a director, you can do D I r for directory,
and it will show you what's in there.
Now, if you see
we have a couple different folders here,
let's say we want to go find users. So you see,
and then users
they were in the users. Now we can see what's inside of users. We have a couple users.
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
we're going Thio, move to my folder
and notice Now that I'm in my folder
Now, we're also going thio
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
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,
and now we're in a different location.
So next, let's get our location and we see where in documents.
Now work it a pop to the last location. We are thin with top location,
and you could see it there. But you could also do get location to see what we're currently act.
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
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,
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
instead, a set location or CD or CH ter or any of things like that.
That's it for our demo first locations. Now it's off to quiz time.
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.
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.
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.
So that's it for this video. In this video, we talked about locations