PowerShell: Getting To Know PowerShell by Dan Riley

PowerShell: Getting To Know PowerShell by Dan Riley

Author:Dan Riley
Language: eng
Format: azw3
Published: 2017-09-02T07:00:00+00:00


Chapter Eleven

ForEach, If/Then,

Do While Statements

Being that you understand how variables are stored in Powershell, what do you do with those variables that you have put into the program?

If/ Then

The if then statement is going to be one of the simplest forms of decision making that you can use when using Powershell. Basically, with this decision-making method, you will be constructing an if-then statement for the program to execute.

If there is something that must be compared to something else, you will then do this.

How you intend to format your statement will be based on the placement of your comparison that is inside of the parentheses before the left curly bracket is placed on a new line where you are going to add in your cmdlet or any actions that need to be performed before a new line is started. To finish off the code, you need to place off another curly bracket.

A few things to keep in mind when it comes to the if / then statements are:

Your comparison statements should have a logical response. There are only two responses that you will get and those are true or false. Basically, you must look at it as if it is a yes or no question that you are trying to answer except you are comparing two objects. If you do not get a true or false answer, then you will be creating a loop.

The code you use to execute your statement will give you a yes or no that will need to be placed inside a set of curly brackets. You have to place these brackets around the line to match them up or else your script will be more complicated than it needs to be.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.