WEBVTT

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

00:03.300 --> 00:05.310
and this is
PowerShell scripting.

00:05.310 --> 00:07.365
In this lesson, we're
going to learn about

00:07.365 --> 00:10.575
piping commands and
piping output to a file.

00:10.575 --> 00:12.180
We learned a little bit about

00:12.180 --> 00:15.074
>> piping in our help lesson.

00:15.074 --> 00:18.460
>> In this lesson we're
going to go further into it.

00:19.040 --> 00:21.960
First of all, Piping Commands,

00:21.960 --> 00:24.060
there are a couple of
very useful commands

00:24.060 --> 00:26.445
that you can pipe that
you really should know,

00:26.445 --> 00:30.150
Where-object, format-List or FL,

00:30.150 --> 00:34.660
format Table or FT,
and measure-object.

00:34.700 --> 00:37.620
Where-object, this is

00:37.620 --> 00:40.860
the first cmdlet that will
be very useful for you.

00:40.860 --> 00:44.000
Allows you to specify certain
conditions that must be

00:44.000 --> 00:47.120
met for the command
in order to run.

00:47.120 --> 00:49.810
For example, here we
have a get-service,

00:49.810 --> 00:53.885
where-object, property
status equals stopped.

00:53.885 --> 00:57.995
What this will do is it'll
get the current services,

00:57.995 --> 01:01.250
then filter them based
on their status.

01:01.250 --> 01:04.760
This one says status
equals stopped,

01:04.760 --> 01:07.310
it's going to look for
that where it says

01:07.310 --> 01:08.780
stopped and it's going to show

01:08.780 --> 01:10.810
all the ones that are stopped.

01:10.810 --> 01:14.385
Now, one thing to
notice is the -eq.

01:14.385 --> 01:18.390
Usually you want to do -eq and

01:18.390 --> 01:20.705
seven-equals sign
when you're trying to

01:20.705 --> 01:22.100
say that something equals

01:22.100 --> 01:24.600
something in a
PowerShell command.

01:25.280 --> 01:29.835
Format-List is the
next useful command.

01:29.835 --> 01:34.550
Format-Lists allows you to
format the output in a list,

01:34.550 --> 01:38.450
for example here we have
get w my on object when

01:38.450 --> 01:40.460
3200 sewer processor and

01:40.460 --> 01:42.830
we have formatted
the list using FL.

01:42.830 --> 01:46.820
You can use Format-List or
you can type in just FL,

01:46.820 --> 01:49.060
either works in PowerShell.

01:49.060 --> 01:51.800
Now, this particular command
is going to look for

01:51.800 --> 01:55.130
some processor information
then displayed as a list.

01:55.130 --> 01:58.040
As you can see here
in the picture,

01:58.040 --> 02:01.670
we have different pieces of
information like caption,

02:01.670 --> 02:03.050
which is usually just some basic

02:03.050 --> 02:04.865
information about the item,

02:04.865 --> 02:08.015
device ID, manufacturer,
and so forth.

02:08.015 --> 02:09.515
Because it's in a list,

02:09.515 --> 02:11.150
is a little bit easier to

02:11.150 --> 02:13.310
read than it would
be in a table.

02:13.310 --> 02:16.040
Now, there are other parameters
that can be used with

02:16.040 --> 02:19.925
Format-List to further
organize the list.

02:19.925 --> 02:21.980
However, that's beyond what

02:21.980 --> 02:23.314
>> we're going to be doing here.

02:23.314 --> 02:24.665
>> But that is something to be

02:24.665 --> 02:27.665
aware of that you
can look for later.

02:27.665 --> 02:32.505
Another formatting option
is Format-table or FT.

02:32.505 --> 02:34.850
Format-table allows
you to format

02:34.850 --> 02:37.520
your output as a
table, for example,

02:37.520 --> 02:41.490
here we have get process
and FT. You can see

02:41.490 --> 02:43.160
here it is now a table

02:43.160 --> 02:45.620
and each table has
a heading here,

02:45.620 --> 02:49.700
so like handles and PM, PM, Ws,

02:49.700 --> 02:52.460
all that has its own column,

02:52.460 --> 02:56.545
and each row is a different
piece of information.

02:56.545 --> 02:59.780
Now, Format-table also has

02:59.780 --> 03:01.100
some additional parameters for

03:01.100 --> 03:04.040
further organization
that you can use.

03:04.040 --> 03:06.275
Again, those are
beyond this video,

03:06.275 --> 03:08.360
but that is something
that you could look into.

03:08.360 --> 03:10.130
Other thing with Format-table

03:10.130 --> 03:11.570
just like Format-List if you

03:11.570 --> 03:14.660
do FT instead of the
full Format-table,

03:14.660 --> 03:17.010
that will also work.

03:17.090 --> 03:22.640
Measure-object is a another
very useful command.

03:22.640 --> 03:26.315
This command allows you
to find metadata or

03:26.315 --> 03:27.890
certain pieces of information

03:27.890 --> 03:30.200
about an object, such as a file.

03:30.200 --> 03:32.000
For example, here we have

03:32.000 --> 03:34.189
>> a command get
child item path,

03:34.189 --> 03:37.535
>> the path of the file,
then measure object.

03:37.535 --> 03:41.690
What this actually
did was it went

03:41.690 --> 03:48.230
through and it found the C
Windows system 32 directory.

03:48.230 --> 03:50.690
Then it got all the child items,

03:50.690 --> 03:52.550
which are all the items

03:52.550 --> 03:54.895
that are actually just
listed in that folder.

03:54.895 --> 03:56.850
Then provided information.

03:56.850 --> 03:58.400
Here it's very simple.

03:58.400 --> 03:59.720
It just gave you account of

03:59.720 --> 04:01.430
how many items in

04:01.430 --> 04:03.770
this particular folder on
this particular computer,

04:03.770 --> 04:06.860
it looks like
there's 4,490 items.

04:06.860 --> 04:09.920
You'll also see some other
items like average son,

04:09.920 --> 04:12.920
maximum, minimum property,
stuff like that,

04:12.920 --> 04:17.000
that using in yet there
are additional parameters

04:17.000 --> 04:18.650
just like with format table and

04:18.650 --> 04:22.040
format list that you can use
to find more information.

04:22.040 --> 04:25.585
One of the very
useful ones is -word,

04:25.585 --> 04:28.560
-word gets word count.

04:28.560 --> 04:31.070
That's pretty cool if you're
working on a file like

04:31.070 --> 04:33.815
a Word file or another
type of document,

04:33.815 --> 04:35.300
you can actually get word count

04:35.300 --> 04:37.530
>> without opening the file.

04:39.009 --> 04:41.465
>> Another item,

04:41.465 --> 04:43.250
you're going to want to
know what piping is,

04:43.250 --> 04:45.455
how to pipe output to a file.

04:45.455 --> 04:48.560
In addition to actually being
able to pipe in commands,

04:48.560 --> 04:51.140
you can actually pipe
your output to a file.

04:51.140 --> 04:55.025
This is very useful for
commands to get information,

04:55.025 --> 04:59.200
such as the CIM instance item.

04:59.200 --> 05:01.610
This one shows when 32BIOS,

05:01.610 --> 05:03.875
which is bios information.

05:03.875 --> 05:06.080
What you can do is you can run

05:06.080 --> 05:08.570
the commands as a
script and create

05:08.570 --> 05:10.400
files so you have all pieces of

05:10.400 --> 05:13.520
information about
what you need to get.

05:13.850 --> 05:16.890
To pipe output to a file,

05:16.890 --> 05:19.820
use the greater than
symbol twice at

05:19.820 --> 05:21.140
the end of your command and

05:21.140 --> 05:23.165
specify the file to pipe it to.

05:23.165 --> 05:25.040
For example, here,

05:25.040 --> 05:29.030
we have our 32Bios and we want

05:29.030 --> 05:30.560
to actually put that to

05:30.560 --> 05:33.805
a text document so we
have it for later.

05:33.805 --> 05:36.440
What we've done is we've
done our commands,

05:36.440 --> 05:41.045
so get-CIM instance -class name

05:41.045 --> 05:48.735
Win32_bios and then our
pipe, then space FL.

05:48.735 --> 05:50.240
We're actually going
to format it as

05:50.240 --> 05:52.655
a list before we put
it in the document.

05:52.655 --> 05:59.385
Then we did our two greater
than symbols BIOS.text,

05:59.385 --> 06:01.910
that's the name of the
file we're sending it to.

06:01.910 --> 06:05.330
There, you can actually
put an entire file path.

06:05.330 --> 06:07.535
The file does not
have to be created.

06:07.535 --> 06:08.780
It will create one for you,

06:08.780 --> 06:11.275
if you have not created it yet.

06:11.275 --> 06:13.430
Once that command runs,

06:13.430 --> 06:15.575
and it's going to pipe
that bios information

06:15.575 --> 06:17.720
into a text file called bios.

06:17.720 --> 06:20.420
You do see there in
the screenshot that

06:20.420 --> 06:24.180
it pipe the output
into a file for you.

06:25.220 --> 06:28.720
Now, post-assessment
question time.

06:28.720 --> 06:30.470
If you wanted to pipe output to

06:30.470 --> 06:32.660
a file called random.txt,

06:32.660 --> 06:33.730
which is a text file,

06:33.730 --> 06:36.085
which command would you use?

06:36.085 --> 06:39.960
Would you pipe random.txt?

06:39.960 --> 06:43.590
Would you greater
than random.txt?

06:43.590 --> 06:47.700
Would you do two greater
than random.txt?

06:47.700 --> 06:52.110
Or would you do a
less than random.txt?

06:52.110 --> 06:55.670
Now, you may pause for
a moment if you want,

06:55.670 --> 06:58.200
and we'll get the
answer in a second.

06:59.900 --> 07:03.020
The answer is C. You would use

07:03.020 --> 07:05.345
the double greater
than random.txt.

07:05.345 --> 07:07.730
Remember, you have to
use the double greater

07:07.730 --> 07:11.280
than when piping
output to a file.

