PowerShell Control Flow – Conditionals and Loops
So far, everything we have done has been one thing after another, to paraphrase Arnold Toynbee. That’s fine, but it doesn’t reflect how we want things to happen in the real world. Most of the time, we want our code to do different things depending on the circumstances, and sometimes we want it to do something a number of times. This is where control flow is necessary. In this chapter, we are going to look at how to make PowerShell do different things in a script, depending on what it finds – these are called conditionals. Then we are going to look at how to make PowerShell repeat a process, both for a predetermined number of times and for an indefinite number. Because an indefinite number may be effectively infinite, we are going to look at how to break out of and continue looping behavior.
Doing this effectively requires writing multiple lines of code, so first, we are going to talk about Integrated Development...