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 Switch statement

As a best practice, you generally avoid using the ElseIf type of construction from either VBScript or Windows PowerShell because there is a better way to write the same code.

In VBScript, you would use the Select Case statement to evaluate a condition and select one outcome from a group of potential statements. In the DemoSelectCase.vbs script, the value of the variable a is assigned the value of 2. The Select Case statement is used to evaluate the value of the variable a. The syntax is shown here:

Select Case testexpression

The test expression that is evaluated is the variable a. Each of the different cases contains potential values for the test expression. If the value of the variable a is equal to 1, the code Wscript.Echo ...

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