The four reach construct has the same purpose as the for each object complete.
That purpose is to enumerate through a collection of objects so that you can work with one object at
a time.
The construct has a different syntax than the complete note.
The for each object complete has an alias for each that is the same as the for each construct keyword.
However, the complete and the construct are not the same.
Windows PowerShell decides whether you are using the LED or the construct based on its position on the
command line.
Although both the construct and the complete have the same purpose, they do not use the same syntax.
The construct looks as follows The computer names equals get content names dot text for each dollar
name and dollar computer names.
Write the current name as dollar name.
In this example, names date text has one computer name per line.
Those are loaded into dollar computer name as individual string objects to make dollar computer name
a collection.
The for each construct enumerates through those one at a time.
The variable on the left side of the in keyword will contain one object at a time from the variable
on the right side of the keyword.
In other words, one computer name at a time will be taken out of the computer name and added into dollar
name.
The command or commands in the script block will execute one time for each object in the dollar computer
name variable.
Because most Windows PowerShell users prefer scripts that are easy to read and maintain.
It is a common practice to use similar variable names in the for each construct.
For example, dollar services equals get service.
For each dollar service in dollar services.
Right.
The current service is dollar.
Dollar service dot name.
However, this naming practice is not a technical requirement.
The following example also works correctly.
Dollar X equals get service.
For each dollar z in x write the current service is dollar Z.
This second example is not as easy to read because the names Dollar X and Dollar Z do not provide any
indication or reminder of what the variables contain.