Controlling Your Code's Flow with PowerShell's Control Statements
PowerShell Control Statements Windows PowerShell provides several ways to control the flow of code. You can use conditional statements to define conditions and the actions to occur when those conditions are met. You can even specify the actions to occur when a condition isn’t met. PowerShell Control statements can be broken down into three sections: Conditional statements Used when you want to execute line of code depending upon some condition. Looping statements Used when you want to perform some task multiple time. Flow control statements Used along with conditional and loop statements to control the flow of execution. Lets go through all, one by one: Conditional statements if statement - execute the script if condition evaluates to true. elseif statement - execute the script if condition evaluates to true and all if, elseif conditions before it false. else statement - execute the scripts that follows it when none of the conditions in if, elseif evaluates to true. Syntax ...