WEBVTT

00:00.000 --> 00:03.300
>> Hello, everyone. I'm
Instructor Gerri Roberts,

00:03.300 --> 00:05.070
and this is
PowerShell Scripting.

00:05.070 --> 00:06.720
In this video,

00:06.720 --> 00:08.505
we're going to learn
some more commands.

00:08.505 --> 00:11.790
We're going to actually
look at locations,

00:11.790 --> 00:13.740
more specifically working with

00:13.740 --> 00:16.950
your current location or
your working directory.

00:16.950 --> 00:19.245
We're going to work
with get-location,

00:19.245 --> 00:21.420
set-location, and we're going to

00:21.420 --> 00:24.880
learn about push-location
and pop-location.

00:25.100 --> 00:28.170
First of all, getting
your current location.

00:28.170 --> 00:29.640
When you're in
PowerShell, you can

00:29.640 --> 00:31.200
find out what your
working directory

00:31.200 --> 00:34.425
is by using the
get-location command.

00:34.425 --> 00:36.000
This will display the path of

00:36.000 --> 00:38.740
the current working
directory for you.

00:39.050 --> 00:42.070
If you want to set
your location,

00:42.070 --> 00:46.310
you can change it by
doing set-location.

00:46.310 --> 00:48.830
Now, one thing to note
that inside a PowerShell,

00:48.830 --> 00:51.815
you can still use CD, CHDIR,

00:51.815 --> 00:54.880
SL or any of the commands
that you normally can use in

00:54.880 --> 00:59.315
the command line prompt
to change your location.

00:59.315 --> 01:01.640
Now, set-location will

01:01.640 --> 01:05.325
actually set the location
of your working directory,

01:05.325 --> 01:08.015
and when you do it,

01:08.015 --> 01:09.890
the prompt will
change to reflect

01:09.890 --> 01:11.510
the new directory just as

01:11.510 --> 01:13.850
CD or any of those
commands will.

01:13.850 --> 01:15.590
When you're doing the command,

01:15.590 --> 01:18.935
you do set-location -path,

01:18.935 --> 01:22.340
-path specifies the directory
that you're going to.

01:22.340 --> 01:23.960
If you want to display

01:23.960 --> 01:26.015
some more information
about the change,

01:26.015 --> 01:31.520
you can use the -passthru
parameter switch

01:31.520 --> 01:34.190
at the end so that way

01:34.190 --> 01:35.814
>> it will display
more information.

01:35.814 --> 01:37.970
>> Now, passthru may
also be used with

01:37.970 --> 01:40.670
some other commands to get
additional information.

01:40.670 --> 01:44.030
It's not specific to
set or get-location.

01:44.030 --> 01:48.650
You can also save your
locations or recall them

01:48.650 --> 01:52.054
>> later using something
called push and pop.

01:52.054 --> 01:54.650
>> Push allows you to save

01:54.650 --> 01:57.095
the current location
in the stack.

01:57.095 --> 01:58.685
Now, the stack is like

01:58.685 --> 02:01.190
any other stack that
you normally work with.

02:01.190 --> 02:03.470
It's first in, last out.

02:03.470 --> 02:06.950
So that means the last
location you put in will be

02:06.950 --> 02:11.030
taken off the top of the
stack when you go to pop it.

02:11.030 --> 02:16.910
Now what pop does is
it takes you back to

02:16.910 --> 02:20.839
the most recently saved
directory by pulling

02:20.839 --> 02:22.880
the top location off of

02:22.880 --> 02:26.730
the stack and then
bringing you there.

02:28.040 --> 02:31.160
Now it is time for a demo so you

02:31.160 --> 02:33.790
can see what those
commands look like.

02:33.790 --> 02:35.300
Now let's take a look at

02:35.300 --> 02:37.309
>> some of those
location commands.

02:37.309 --> 02:39.515
>> The first one
is get-location.

02:39.515 --> 02:40.820
That's pretty much just going

02:40.820 --> 02:42.544
>> to give us a current path.

02:42.544 --> 02:46.230
>> So get-location,
and you can see

02:46.230 --> 02:47.385
that currently

02:47.385 --> 02:50.830
our working directory
is C:\WINDOWS\system32.

02:50.830 --> 02:54.650
Now this might be important
because some commands

02:54.650 --> 02:59.255
actually are impacted by the
current working directory,

02:59.255 --> 03:02.510
so you want to make sure
you're in the right place.

03:02.510 --> 03:07.680
Now, the next thing you
can do is set-location.

03:07.680 --> 03:10.670
Now, set-location
will allow you to set

03:10.670 --> 03:13.790
the location to a place
you'd like to go.

03:13.790 --> 03:16.040
It's very similar
to the way that

03:16.040 --> 03:19.370
CD works in that if you were to

03:19.370 --> 03:26.260
say cd to c and then Windows,

03:26.260 --> 03:29.295
you see how you
change into Windows.

03:29.295 --> 03:31.380
If you were to cd back

03:31.380 --> 03:40.530
into C:\Windows\system32,

03:40.530 --> 03:43.575
you would go back to system32.

03:43.575 --> 03:47.835
When you do set-location,
it's pretty similar.

03:47.835 --> 03:51.910
What you do is you
do set-location,

03:51.910 --> 03:55.460
and then you do the
path parameter,

03:55.460 --> 03:57.320
and then you do the path.

03:57.320 --> 03:59.000
Here, let's go ahead and

03:59.000 --> 04:02.200
do c:\windows like
we did with CD,

04:02.200 --> 04:05.675
and you can see that it
does a very similar thing.

04:05.675 --> 04:07.580
Now, if we want to go back,

04:07.580 --> 04:11.360
we can do the same
thing and just put

04:11.360 --> 04:16.230
our system32 path. There you go.

04:16.230 --> 04:18.930
So that's setting location.

04:18.930 --> 04:20.670
Now, another thing with

04:20.670 --> 04:22.380
set-location that
we talked about

04:22.380 --> 04:25.665
was the passthru command.

04:25.665 --> 04:27.380
Now you noticed when
we were setting

04:27.380 --> 04:29.990
the location in these
two other spots,

04:29.990 --> 04:31.850
we didn't get a confirmation.

04:31.850 --> 04:33.290
The only thing we got was that

04:33.290 --> 04:35.120
the prompt change the directory.

04:35.120 --> 04:38.570
If we want some sort of
confirmation and information,

04:38.570 --> 04:41.905
we can use passthru at the end.

04:41.905 --> 04:43.700
Look at that, we get

04:43.700 --> 04:46.970
an actual path and it shows
us where it's going to go.

04:46.970 --> 04:49.475
Lastly, we want to look

04:49.475 --> 04:52.730
at saving and recalling
recent locations,

04:52.730 --> 04:57.345
which are push and pop commands.

04:57.345 --> 04:59.630
What we're going to do
is we're going to get

04:59.630 --> 05:02.135
our current location
to see where we're at,

05:02.135 --> 05:05.850
which we know is in system32.

05:05.850 --> 05:10.880
Then we're going to
change our location

05:10.880 --> 05:14.015
by going ahead and

05:14.015 --> 05:17.395
pushing the current
location onto the stack.

05:17.395 --> 05:26.550
So we do push-location path,

05:26.550 --> 05:28.790
and then we're going to
move to the local settings

05:28.790 --> 05:33.480
folder by doing a path
in local settings.

05:33.480 --> 05:38.370
Now, push works
like set-location,

05:38.370 --> 05:40.130
but instead of just moving,

05:40.130 --> 05:44.030
what it does is it pushes
your current location onto

05:44.030 --> 05:48.545
the stack and then goes to
the location you tell it.

05:48.545 --> 05:51.875
Here, we're going
to go ahead and

05:51.875 --> 05:56.690
push the local settings to
where we're going to go,

05:56.690 --> 06:02.550
and then we're going to save
the system32 in our stack.

06:02.990 --> 06:05.710
Now notice I got an error.

06:05.710 --> 06:08.270
That's actually because there is

06:08.270 --> 06:11.065
no local settings in system32.

06:11.065 --> 06:13.160
Your local settings folders are

06:13.160 --> 06:17.190
actually in your users folder.

06:17.590 --> 06:21.070
If you put the wrong path,

06:21.070 --> 06:22.710
it's not going to find

06:22.710 --> 06:24.125
it and you're going
to get an error,

06:24.125 --> 06:26.240
and it's just going to
stay in the current path.

06:26.240 --> 06:31.025
Now we can also try
maybe going to a user.

06:31.025 --> 06:34.880
Let's do actually cd

06:34.880 --> 06:39.530
c. If you want to see
what's in a directory,

06:39.530 --> 06:41.765
you can do dir for directory,

06:41.765 --> 06:44.330
and it'll show you
what's in there.

06:44.330 --> 06:46.940
Now, if you see, we

06:46.940 --> 06:50.045
have a couple of
different folders here.

06:50.045 --> 06:53.315
Let's say we want
to go find users.

06:53.315 --> 06:59.220
We can go cd and then users,

07:00.140 --> 07:02.460
and we are in users.

07:02.460 --> 07:04.710
Now we can see what's
inside of users.

07:04.710 --> 07:06.655
We have a couple of users.

07:06.655 --> 07:08.620
Now this is where we're
going to go ahead and

07:08.620 --> 07:10.715
do some push and pop.

07:10.715 --> 07:14.530
We're going to push the current
location onto the stack,

07:14.530 --> 07:20.940
and then we're going
to move to my folder.

07:20.940 --> 07:24.915
Notice now that I
am in my folder.

07:24.915 --> 07:29.250
Now we're also going to change

07:29.250 --> 07:31.630
again so we have
another location in

07:31.630 --> 07:32.860
the stack because
we're going to try to

07:32.860 --> 07:34.465
build up the stack here.

07:34.465 --> 07:40.050
I'm going to do directory
to see what's in there.

07:40.050 --> 07:41.720
You can see all sorts of stuff,

07:41.720 --> 07:44.285
but we're going to go ahead and

07:44.285 --> 07:47.735
go to the documents folder.

07:47.735 --> 07:51.305
We're going to push-location.

07:51.305 --> 07:55.500
That's going to save our
current item in our stack,

07:55.500 --> 07:56.550
and then we're going to

07:56.550 --> 07:59.530
path and we are
going to documents.

07:59.720 --> 08:04.080
Now we're in a
different location.

08:04.080 --> 08:06.660
Next, let's get

08:06.660 --> 08:11.715
our location and we see
we're in documents.

08:11.715 --> 08:15.170
Now we're going to pop
to the last location

08:15.170 --> 08:18.930
we are in with pop-location.

08:19.580 --> 08:21.855
You can see it there,

08:21.855 --> 08:25.250
but you can also do
get-location to see where

08:25.250 --> 08:28.830
we're currently at.
It's kind of cool.

08:28.830 --> 08:31.905
You can save it in the
stack and then go back.

08:31.905 --> 08:34.950
You can keep going back to

08:34.950 --> 08:38.405
all your saved locations

08:38.405 --> 08:40.955
until you hit the
end of the stack.

08:40.955 --> 08:43.880
That's useful if
you're working in

08:43.880 --> 08:47.305
multiple locations and
want to go back and forth.

08:47.305 --> 08:49.534
But just make sure

08:49.534 --> 08:51.815
that when you're pushing
and you're popping,

08:51.815 --> 08:53.540
that you remember where you're

08:53.540 --> 08:55.790
at because it's
easy to get lost.

08:55.790 --> 09:01.220
But this is also an easy
way to have the ability to

09:01.220 --> 09:02.750
go back and forth between

09:02.750 --> 09:06.420
different locations
in set-location,

09:06.420 --> 09:08.100
or CD, or CHDIR,

09:08.100 --> 09:10.425
or any other things like that.

09:10.425 --> 09:14.850
That's it for our
demo for locations.

09:14.850 --> 09:17.115
Now it's off to quiz time.

09:17.115 --> 09:19.940
In this quiz, we want to
know if you wanted to get

09:19.940 --> 09:22.565
back to the most recently
saved location in the stack,

09:22.565 --> 09:24.425
which command would you use?

09:24.425 --> 09:26.480
Would you use push-location,

09:26.480 --> 09:31.175
set-location, get-location,
or pop-location?

09:31.175 --> 09:33.230
I give you a minute
to figure that out.

09:33.230 --> 09:35.150
You can also pause if you want,

09:35.150 --> 09:37.470
and then we'll give the answer.

09:39.080 --> 09:42.540
All right. The answer
is D, pop-location.

09:42.540 --> 09:44.900
Remember, pop-location
allows you to pop

09:44.900 --> 09:47.060
that last saved location in

09:47.060 --> 09:50.060
the stack so you
can go back to it.

09:50.060 --> 09:52.610
This is due to the
stack being FILO,

09:52.610 --> 09:54.755
remember first in, last out.

09:54.755 --> 09:58.100
It's like a stack of books.

09:58.100 --> 10:01.050
The last book you
put in you can grab.

10:01.240 --> 10:03.605
That's it for this video.

10:03.605 --> 10:06.900
In this video, we
talked about locations.

