Enumeration is a process of performing a task on each object in a collection one at a time.
Frequently windows power Schild does not require you to explicitly enumerate objects.
For example if you're needed to stop every neuron in mode but promises on your computer you could either
of these two commands get process name notepad by stop process or stop process name.
Note Pad one common scenario that requires enumeration is when you have to executor a method or an object
and no Come on provide the same functionality as that method.
For example the objects produced by get objects have a kill method that stops that process.
But you might not ever use that method because the stop process command doesn't the same theme.
Consider the kind of object Prady used when you're around get child died.
File on a disk drive this object type system your file in for has a mass of named and grid that can
encrypted file by you than a current user accounts and grippers certificate more equivalent command
is built into Windows POAs shells so you might have to exec get that method on manif file object that
you want to do in Grebe enumeration enables you to do this with a single command enumeration is performed
by the foreach object command.
It has two common aliases for each and are of sound character.
So what is basic enumeration semantics like.
Where object foreach object has a basic syntax and an advanced syntax and the basic syntax you can executor
a single method or access a single property of the objects that are piped into the command.
For example gay child died in pass C drive encrypted file by battue for each object.
This member name and gripped with this syntax do not include the parenthesis after their member name.
If the member either method because this basic syntax is meant to be short you will frequently see it
written without the member name parameter.
And to you you may see it returned with an alias instead of the full command name.
For example all the Folarin will perform the same action child item path C C-Drive encrypted file type
it to foreach encrypt or get child item pass C-Drive encrypted this file and pipe it to a very sound
character encrypt.
So this is how you can shorten these long commands.
You may not discover many scenarios where you have to use enumeration.
Then don't say it Windows Server 2012 for example introduced thousands of new windows power shell commands.
Many of those new commands perform actions that previously required enumeration some Goethe's about
limitations of the basic syntax.
The basic syntax can access only a single property or method.
It cannot perform logical comparisons that use and and or it cannot make decisions and it cannot exec
it any other commands or code.
For example the following in will will not run good service by their name.
The like as in quotes with asterisks and operator status equal Ronon.
Now let's have some demonstration examples and this example to seek out to you the basic enumeration
syntax to enumerate several objects in a collection.
First example will display only the name of every service installed on the computer to do a letter it
should run get serviced by for each name.
Such a simple example.
Another example will use enumeration to clear the system event log.
To do that which should run get around clock test least by where lock equals system Y foreach clear.
As I have mentioned there is advanced enumeration syntax the advanced syntax for enumeration provides
more flexibility and functionality instead of letting you access a single object member.
You can executor a whole script that script may include just one command or may include many commands
in sequence for example to encrypt a set of files by using advanced syntax.
You could run the following command Getchell diet and pass C drive to encrypt the file by foreach object
does process Antrel use Pierres item don't encrypt followed by parenthesis.
And don't forget about curly braces for each object command which had the LS foreach and sound character
can accept any number of objects from the pipeline.
It has a process parameter that accepts a script.
BLOCK This script Gloc real executor one time for each object that was piped in every time that the
script block executor's the built in variable P.S. item or Dolor character underscore can be used to
refer to a current object in the preceding example command that encrypt method of each file object is
executor.
When they are used to really advance syntax method names are always followed by opening and closing
parenthesis even when the master does not have any input arguments.
For example that do not need in good arguments for why them as a comma separated list inside the parenthesis.
You may not include a space or other characters between the method name and the open in parenthesis.
In some situations you may need to repeat a given task for a specified number of times for each object
can be used for that purpose.
When you use it at the same time the range of operator for example from want to turn over a 1 to 100.
You type it like one dot dot one Kondrat then followed by bibe character for each object.
Get random in curly braces and this command the range operator is used to produce integer objects from
1 through one Kondrat the range operator is two periods.
As I've mentioned there's no space in between them.
Lose 100.
Objects are piped to for each object.
Command force and it forth in its script block to exact 100 times.
However because neither dollar character underscore nor the US item appear in the script block the actual
integers are not used instead the command get random is around 100 times the interviewer.
Objects are used only to set the number of times there's gridlock.
Executor's not a small task for you.
Make up some small example one example where you could use this range operator.
Now let's have some demonstration examples with this advanced enumeration techniques.
You'll see two ways to use advanced enumeration syntax to perform tasks against several objects and
the first example will modify all items in Edge current user murtherer key so that all names are uppercase.
To do that we could run the file command get a property path then followed by pipe for each object.
There's process and set Item property command in curly braces and the second example we have to produce
a list of grossers names to a text file that is name Broks that takes t and include the current date
at the beginning of the file to do that.
Run get roses pide for each object does begin and get the date command and go to the braces and then
out file rocks that XTi and out file Raupp that takes the band so that will produce a list of grossers
names and save them to a file to a txt file.