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

In VBScript, the If...Then...End If statement was somewhat straightforward. There were several things to be aware of:

  • The If and the Then statements must be on the same line.

  • The If...Then...End If statement must conclude with End If.

  • End If is two words, not one.

The VBScript If...Then...End If statement is shown in the DemoIf.vbs script:

DemoIf.vbs

a = 5
If a = 5 Then
 WScript.Echo "a equals 5"
End If

In the Windows PowerShell version of the If...Then...End If statement, there is no Then keyword, nor is there an End If statement. The PowerShell If statement is easier to type. This simplicity, however, comes with a bit of complexity. The condition that is evaluated in the If statement is positioned between a set of parentheses. ...

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