WEBVTT

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

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

00:05.490 --> 00:07.410
In this video,
we're going to talk

00:07.410 --> 00:08.840
about what a command is,

00:08.840 --> 00:12.165
and how commands are
structured in PowerShell.

00:12.165 --> 00:15.045
First of all, what is a command?

00:15.045 --> 00:17.220
Simply put, a command
is just a bunch of

00:17.220 --> 00:19.920
words or a single word that's

00:19.920 --> 00:22.080
been put together to do

00:22.080 --> 00:24.660
>> something such
as Get- EventLog,

00:24.660 --> 00:27.465
>> which would help you retrieve
an EventLog in Windows.

00:27.465 --> 00:29.220
In PowerShell, they
are also called

00:29.220 --> 00:31.740
cmdlets, or commandlets.

00:31.740 --> 00:35.175
There are pre-defined
cmdlets in PowerShell,

00:35.175 --> 00:37.135
and some that you can add.

00:37.135 --> 00:39.785
Packages of commands are
often called modules.

00:39.785 --> 00:42.740
There are modules for some
things that you can add.

00:42.740 --> 00:45.470
These could be for a
program or a specific task.

00:45.470 --> 00:47.210
For example, there are modules

00:47.210 --> 00:49.175
specifically made for Azure,

00:49.175 --> 00:51.410
and there are
actual modules made

00:51.410 --> 00:54.990
specifically for
scripting tasks.

00:55.940 --> 00:59.300
In PowerShell, there's usually

00:59.300 --> 01:02.495
a structure to the
command or the cmdlet.

01:02.495 --> 01:04.790
Here we have an example of

01:04.790 --> 01:08.485
a command that's trying
to get an EventLog,

01:08.485 --> 01:11.180
and specifically looking
for the one called

01:11.180 --> 01:15.470
Security on the
computer Gerri-PC2.

01:15.470 --> 01:17.540
At the end, we're
telling it that

01:17.540 --> 01:19.490
we want a lot of information.

01:19.490 --> 01:21.500
Verbose means that you're going

01:21.500 --> 01:23.780
to add a lot of
extra information.

01:23.780 --> 01:25.670
Now if we break
down this command,

01:25.670 --> 01:27.544
we can see that
at the beginning,

01:27.544 --> 01:29.720
the first item is a verb,

01:29.720 --> 01:31.460
the second item is a noun.

01:31.460 --> 01:33.319
Typically in PowerShell,

01:33.319 --> 01:35.870
commands are structured
with a verb, noun.

01:35.870 --> 01:38.920
This one's a Get-EventLog,

01:38.920 --> 01:40.200
and a lot of times you have

01:40.200 --> 01:42.550
commands that are
Get- something.

01:42.550 --> 01:45.245
You'll also have
commands that are Set-

01:45.245 --> 01:48.420
something or Add-
something a lot.

01:48.420 --> 01:50.120
Now the difference here is

01:50.120 --> 01:51.740
>> when you do a Get- something,

01:51.740 --> 01:54.020
>> you're usually just
pulling information.

01:54.020 --> 01:56.270
When you're doing
a Set- something,

01:56.270 --> 01:58.580
you're usually actually
setting a value

01:58.580 --> 02:01.790
such as a username or a
password for an account.

02:01.790 --> 02:04.545
If you're doing an
Add- something,

02:04.545 --> 02:06.920
you're usually adding
a new something

02:06.920 --> 02:09.515
like a new user or a new group.

02:09.515 --> 02:11.795
The next thing
you'll notice after

02:11.795 --> 02:14.555
our verb-noun structure
is a parameter.

02:14.555 --> 02:19.565
A parameter is an item where
we can put information in.

02:19.565 --> 02:23.270
Here, we have a parameter
for logged name.

02:23.270 --> 02:25.220
We're telling it that
we're looking for

02:25.220 --> 02:27.670
a specific log and then putting

02:27.670 --> 02:31.970
in a parameter value so it
knows which log to find.

02:31.970 --> 02:34.205
In this case, it's Security.

02:34.205 --> 02:38.500
Now we also have another
parameter here, computer name.

02:38.500 --> 02:40.340
Now we're telling it we're

02:40.340 --> 02:42.320
looking for the
LogName, Security,

02:42.320 --> 02:43.610
and then we're going
to look for it

02:43.610 --> 02:45.395
on this specific computer,

02:45.395 --> 02:48.795
and we pass the value Gerri-PC2.

02:48.795 --> 02:50.600
Now notice here that

02:50.600 --> 02:53.525
these parameters only
have a single value.

02:53.525 --> 02:56.824
Some parameters can
have multiple values,

02:56.824 --> 03:01.100
and those values typically
are separated by

03:01.100 --> 03:03.500
commas or quotation marks

03:03.500 --> 03:04.850
depending on the structure

03:04.850 --> 03:06.964
>> of that particular parameter.

03:06.964 --> 03:09.380
>> Now at the end, you
notice that you do

03:09.380 --> 03:12.060
have a switch parameter.

03:12.060 --> 03:14.320
Now, there are different
types of parameters.

03:14.320 --> 03:16.255
Here we see parameters
that take values,

03:16.255 --> 03:18.040
and such parameter
is a parameter

03:18.040 --> 03:20.125
that does not take your value,

03:20.125 --> 03:22.520
but does do something.

03:24.080 --> 03:28.475
Nouns and parameters are
normally in singular form.

03:28.475 --> 03:30.190
That just means commands and

03:30.190 --> 03:33.655
parameters will not usually
have an s at the end.

03:33.655 --> 03:37.465
Here's an example
we have Get-ADUser.

03:37.465 --> 03:39.070
When we put that command in and

03:39.070 --> 03:40.540
we put it in the dashes for

03:40.540 --> 03:41.650
the parameters and we put

03:41.650 --> 03:43.554
>> in those pieces
of information,

03:43.554 --> 03:45.280
>> we'll be able
to get information

03:45.280 --> 03:47.140
about an Active Directory user.

03:47.140 --> 03:49.720
However, if we added
an s at the end,

03:49.720 --> 03:51.700
and we did Get-ADUsers,

03:51.700 --> 03:53.945
we're going to get a
big old nice block of

03:53.945 --> 03:56.010
red text that's
an error and it's

03:56.010 --> 03:57.314
>> not going to be happy.

03:57.314 --> 04:00.015
>> Make sure when you're
typing it out this command,

04:00.015 --> 04:02.270
that you look and
see is this one

04:02.270 --> 04:05.630
that has an s because
those are very rare.

04:05.630 --> 04:07.880
Sometimes those are things like

04:07.880 --> 04:11.630
Get-process or Get-services
or things like

04:11.630 --> 04:13.325
that from the computer

04:13.325 --> 04:15.410
where the name of
the item already had

04:15.410 --> 04:18.680
an s. Most modules

04:18.680 --> 04:21.710
also have information on
where they come from.

04:21.710 --> 04:23.390
In the example above,

04:23.390 --> 04:24.680
when you look at that cmdlet,

04:24.680 --> 04:28.440
you see the AD for
Active Directory.

04:28.440 --> 04:29.900
Another thing you'll notice when

04:29.900 --> 04:31.205
you're putting in commands,

04:31.205 --> 04:33.335
if it's from a specific module,

04:33.335 --> 04:34.910
you're probably going
to have some sort of

04:34.910 --> 04:37.595
information in it to tell
you where it's coming from,

04:37.595 --> 04:40.895
such as our Active
Directory example.

04:40.895 --> 04:45.390
Now spacing, case-sensitive,
and other considerations.

04:45.390 --> 04:48.315
Watch your spacing, seriously.

04:48.315 --> 04:51.120
Improperly spaced commands
just are not going to run,

04:51.120 --> 04:52.190
you're going to
get a whole lot of

04:52.190 --> 04:54.250
red text and you're
not going to be happy.

04:54.250 --> 04:57.170
PowerShell uses these
spaces to know when

04:57.170 --> 05:00.260
to look for the next
item in the list.

05:00.260 --> 05:02.240
It will continue until it is

05:02.240 --> 05:04.385
lost if there is
not proper spacing.

05:04.385 --> 05:07.340
What will happen is the
command will run and

05:07.340 --> 05:10.020
then if hits where it's
not proper spacing,

05:10.020 --> 05:12.180
it's going to go, oops, I
don't know what that is.

05:12.180 --> 05:13.470
Here's a bunch of errors telling

05:13.470 --> 05:15.435
you that I don't
know what that is.

05:15.435 --> 05:18.585
Another thing with
PowerShell, case-sensitive.

05:18.585 --> 05:20.280
Some modules in PowerShell are

05:20.280 --> 05:22.120
case-sensitive, some are not.

05:22.120 --> 05:23.450
Quite a few of them.

05:23.450 --> 05:25.910
If you were to write
that Get-ADUser we

05:25.910 --> 05:28.910
saw earlier all in
lowercase would still work.

05:28.910 --> 05:31.610
But the important
part to remember is

05:31.610 --> 05:34.295
things that are values
like file paths,

05:34.295 --> 05:36.080
file names, folder paths,

05:36.080 --> 05:37.910
all that should be properly

05:37.910 --> 05:39.980
capitalized to avoid
confusion because it's

05:39.980 --> 05:42.400
not going to find what you
need or do what you need

05:42.400 --> 05:45.004
if it doesn't know
the proper value.

05:45.004 --> 05:46.850
If you're just not
sure if a module

05:46.850 --> 05:49.385
requires proper capitalization,
just do it anyways.

05:49.385 --> 05:51.290
It's not going to hurt to do

05:51.290 --> 05:54.650
capitalization when you
don't need to necessarily.

05:54.650 --> 05:57.529
The other thing,
use proper symbols.

05:57.529 --> 05:59.390
For example, don't
accidentally put

05:59.390 --> 06:02.255
an underscore in a command
that requires a dash,

06:02.255 --> 06:06.775
and put your slashes in
the correct direction.

06:06.775 --> 06:10.425
File paths or anything like
that that requires a slash,

06:10.425 --> 06:12.680
if the slash is in
the wrong direction,

06:12.680 --> 06:14.195
it's not going to find it,

06:14.195 --> 06:15.530
it's not going to do it,

06:15.530 --> 06:17.060
you're going to have a bad day.

06:17.060 --> 06:18.230
Make sure you put your

06:18.230 --> 06:21.150
>> slashes in the
correct direction.

06:21.619 --> 06:25.230
>> Post assessment
question time.

06:25.230 --> 06:27.440
What is a parameter
called that has

06:27.440 --> 06:29.680
no values being
passed through it?

06:29.680 --> 06:31.640
If you remember back
a couple slides,

06:31.640 --> 06:32.915
we talked about that.

06:32.915 --> 06:34.915
Is that a zero parameter,

06:34.915 --> 06:37.230
is that a switch parameter,

06:37.230 --> 06:39.300
is that a blank parameter,

06:39.300 --> 06:41.010
or a parameter null?

06:41.010 --> 06:44.790
You can pause for a moment
to figure out your answers.

06:45.830 --> 06:50.375
Our answer here is B,
a switch parameter.

06:50.375 --> 06:52.550
A switch parameter
has no value being

06:52.550 --> 06:55.460
passed through it and will
only have one effect.

06:55.460 --> 06:58.760
For example, in our
example earlier, verbose.

06:58.760 --> 07:00.440
Verbose is put there to add

07:00.440 --> 07:04.890
additional information about
the output of the item.

