O'Reilly logo

Windows PowerShell™ 3.0 Step by Step by Ed Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The For statement

In VBScript, a For...Next loop was somewhat easy to create. An example of a simple For...Next loop is shown in DemoForLoop.vbs. You use the For keyword, define a variable to keep track of the count, indicate how far you will go, define your action, and ensure that you specify the Next keyword. That is about all there is to it. The DemoForLoop.vbs is shown here:

DemoForLoop.vbs

For i = 1 To 5
 WScript.Echo i
Next

Using the For statement

You can achieve the same thing in Windows PowerShell. The structure of the For loop in Windows PowerShell resembles the structure for VBScript. They both begin with the keyword For, they both initialize the variable, and they both specify how far the loop will progress. One thing that is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required