The if construct is used to make logical decisions.
Its complete syntax looks as follows.
If dollar this IQ, dollar that hashtag condition one else.
If dollar those get dollar these hashtag condition to else.
If dollar this dollar that hashtag condition three.
Else.
Hashtag condition for notice that the hashtag character in Windows PowerShell starts a comment line.
The rest of the line is ignored by the shell.
The if construct has three main components.
The have section is mandatory.
A condition that evaluates to either true or false must be enclosed in parentheses.
Curly braces then enclose a script block.
The script block contains the command or commands that will run if the condition evaluates to true zero
or more elusive sections are next.
Each of these has its own condition and script block.
You are not required to have any else of sections, and you may have as many as you must have.
An optional section comes last.
It does not have a condition.
However, it does have a script block.
The conditions are evaluated in order.
When a condition is found that evaluates to true, the shell executes the corresponding script block
and stops evaluating any other conditions.
If no conditions, evaluate to true and if an L section exists, the L.S. script block will be executed.
As a best practice, the command or commands within each script block should be indented one level.
You can create this indentation by using the tab key in the Windows PowerShell AC.
The preceding formatting is one of two common ways to format this and other constructs.
The following is the other common formatting approach.
If dollar this equals that hashtag condition one.
Else.
Hashtag condition to note in the Windows PowerShell, AC.
You can use the mouse pointer to select multiple lines of text.
You can then press tab or shift plus tab to increase or decrease the indentation level for the selected
lines.