WEBVTT

00:00.420 --> 00:06.990
Enumeration is a process of performing a task on each object in a collection one at a time.

00:06.990 --> 00:12.790
Frequently windows power Schild does not require you to explicitly enumerate objects.

00:12.810 --> 00:19.560
For example if you're needed to stop every neuron in mode but promises on your computer you could either

00:19.770 --> 00:27.540
of these two commands get process name notepad by stop process or stop process name.

00:27.540 --> 00:35.970
Note Pad one common scenario that requires enumeration is when you have to executor a method or an object

00:36.240 --> 00:40.590
and no Come on provide the same functionality as that method.

00:40.590 --> 00:47.010
For example the objects produced by get objects have a kill method that stops that process.

00:47.160 --> 00:53.940
But you might not ever use that method because the stop process command doesn't the same theme.

00:53.940 --> 00:59.450
Consider the kind of object Prady used when you're around get child died.

00:59.670 --> 01:08.430
File on a disk drive this object type system your file in for has a mass of named and grid that can

01:08.430 --> 01:14.450
encrypted file by you than a current user accounts and grippers certificate more equivalent command

01:14.460 --> 01:21.510
is built into Windows POAs shells so you might have to exec get that method on manif file object that

01:21.510 --> 01:28.350
you want to do in Grebe enumeration enables you to do this with a single command enumeration is performed

01:28.380 --> 01:31.210
by the foreach object command.

01:31.260 --> 01:37.010
It has two common aliases for each and are of sound character.

01:37.110 --> 01:40.160
So what is basic enumeration semantics like.

01:40.170 --> 01:47.520
Where object foreach object has a basic syntax and an advanced syntax and the basic syntax you can executor

01:47.760 --> 01:54.250
a single method or access a single property of the objects that are piped into the command.

01:54.300 --> 02:01.540
For example gay child died in pass C drive encrypted file by battue for each object.

02:01.540 --> 02:09.050
This member name and gripped with this syntax do not include the parenthesis after their member name.

02:09.150 --> 02:15.990
If the member either method because this basic syntax is meant to be short you will frequently see it

02:16.080 --> 02:18.910
written without the member name parameter.

02:19.080 --> 02:24.340
And to you you may see it returned with an alias instead of the full command name.

02:24.360 --> 02:32.480
For example all the Folarin will perform the same action child item path C C-Drive encrypted file type

02:32.550 --> 02:41.700
it to foreach encrypt or get child item pass C-Drive encrypted this file and pipe it to a very sound

02:41.700 --> 02:43.280
character encrypt.

02:43.290 --> 02:46.900
So this is how you can shorten these long commands.

02:46.950 --> 02:51.330
You may not discover many scenarios where you have to use enumeration.

02:51.420 --> 02:58.680
Then don't say it Windows Server 2012 for example introduced thousands of new windows power shell commands.

02:58.680 --> 03:05.430
Many of those new commands perform actions that previously required enumeration some Goethe's about

03:05.430 --> 03:07.820
limitations of the basic syntax.

03:07.890 --> 03:12.150
The basic syntax can access only a single property or method.

03:12.270 --> 03:20.440
It cannot perform logical comparisons that use and and or it cannot make decisions and it cannot exec

03:20.490 --> 03:22.880
it any other commands or code.

03:22.920 --> 03:28.560
For example the following in will will not run good service by their name.

03:28.610 --> 03:36.170
The like as in quotes with asterisks and operator status equal Ronon.

03:36.180 --> 03:41.910
Now let's have some demonstration examples and this example to seek out to you the basic enumeration

03:41.910 --> 03:45.990
syntax to enumerate several objects in a collection.

03:45.990 --> 03:52.800
First example will display only the name of every service installed on the computer to do a letter it

03:52.800 --> 03:56.270
should run get serviced by for each name.

03:56.280 --> 03:57.930
Such a simple example.

03:57.930 --> 04:02.880
Another example will use enumeration to clear the system event log.

04:02.940 --> 04:12.620
To do that which should run get around clock test least by where lock equals system Y foreach clear.

04:12.740 --> 04:18.480
As I have mentioned there is advanced enumeration syntax the advanced syntax for enumeration provides

04:18.480 --> 04:24.820
more flexibility and functionality instead of letting you access a single object member.

04:24.840 --> 04:31.500
You can executor a whole script that script may include just one command or may include many commands

04:31.500 --> 04:36.930
in sequence for example to encrypt a set of files by using advanced syntax.

04:36.930 --> 04:45.170
You could run the following command Getchell diet and pass C drive to encrypt the file by foreach object

04:45.280 --> 04:52.200
does process Antrel use Pierres item don't encrypt followed by parenthesis.

04:52.260 --> 05:00.970
And don't forget about curly braces for each object command which had the LS foreach and sound character

05:01.180 --> 05:05.000
can accept any number of objects from the pipeline.

05:05.110 --> 05:08.460
It has a process parameter that accepts a script.

05:08.480 --> 05:15.970
BLOCK This script Gloc real executor one time for each object that was piped in every time that the

05:16.000 --> 05:24.550
script block executor's the built in variable P.S. item or Dolor character underscore can be used to

05:24.550 --> 05:32.640
refer to a current object in the preceding example command that encrypt method of each file object is

05:32.650 --> 05:33.550
executor.

05:33.670 --> 05:40.450
When they are used to really advance syntax method names are always followed by opening and closing

05:40.450 --> 05:45.350
parenthesis even when the master does not have any input arguments.

05:45.400 --> 05:54.060
For example that do not need in good arguments for why them as a comma separated list inside the parenthesis.

05:54.070 --> 06:01.420
You may not include a space or other characters between the method name and the open in parenthesis.

06:01.450 --> 06:09.310
In some situations you may need to repeat a given task for a specified number of times for each object

06:09.310 --> 06:11.580
can be used for that purpose.

06:11.620 --> 06:19.690
When you use it at the same time the range of operator for example from want to turn over a 1 to 100.

06:19.690 --> 06:26.840
You type it like one dot dot one Kondrat then followed by bibe character for each object.

06:26.860 --> 06:34.630
Get random in curly braces and this command the range operator is used to produce integer objects from

06:34.650 --> 06:39.520
1 through one Kondrat the range operator is two periods.

06:39.520 --> 06:42.640
As I've mentioned there's no space in between them.

06:42.740 --> 06:44.100
Lose 100.

06:44.110 --> 06:47.410
Objects are piped to for each object.

06:47.410 --> 06:53.580
Command force and it forth in its script block to exact 100 times.

06:53.590 --> 07:01.810
However because neither dollar character underscore nor the US item appear in the script block the actual

07:02.020 --> 07:09.470
integers are not used instead the command get random is around 100 times the interviewer.

07:09.520 --> 07:14.040
Objects are used only to set the number of times there's gridlock.

07:14.070 --> 07:16.640
Executor's not a small task for you.

07:16.720 --> 07:22.840
Make up some small example one example where you could use this range operator.

07:22.960 --> 07:28.740
Now let's have some demonstration examples with this advanced enumeration techniques.

07:28.780 --> 07:36.790
You'll see two ways to use advanced enumeration syntax to perform tasks against several objects and

07:36.790 --> 07:46.000
the first example will modify all items in Edge current user murtherer key so that all names are uppercase.

07:46.000 --> 07:53.730
To do that we could run the file command get a property path then followed by pipe for each object.

07:53.740 --> 08:02.620
There's process and set Item property command in curly braces and the second example we have to produce

08:02.620 --> 08:10.680
a list of grossers names to a text file that is name Broks that takes t and include the current date

08:10.780 --> 08:13.060
at the beginning of the file to do that.

08:13.060 --> 08:20.830
Run get roses pide for each object does begin and get the date command and go to the braces and then

08:21.070 --> 08:29.830
out file rocks that XTi and out file Raupp that takes the band so that will produce a list of grossers

08:29.830 --> 08:33.910
names and save them to a file to a txt file.
