5

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 ...

Get PowerShell 7 Workshop now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.