September 2010
Intermediate to advanced
1704 pages
111h 8m
English
Often a script needs to loop through items and act on each. PowerShell supports several looping constructs. Examples of the for and foreach constructs are demonstrated here. Others, such as while, also exist but are not covered in this chapter.

The preceding example shows a for loop. The method to jump or way to use a step is shown. A jump or step is indicated by the last part of the preceding for loop, where $i+=2 is used. If this example had used $i++ instead, the output would be each number from 0 to 5.
Here’s an example of using foreach:
In this example, within the foreach scriptblock, any number of commands could have ...
Read now
Unlock full access