Chapter 5. Flow control in scripts

This chapter covers

  • Conditional, looping, and switch statements
  • Labels, break, and continue
  • Flow control with cmdlets
  • Statements as values
  • Performance issues

I may not have gone where I intended to go, but I think I have ended up where I needed to be.

Douglas Adams, The Long Dark Tea-Time of the Soul

Previous chapters showed how you can solve surprisingly complex problems in PowerShell using only commands and operators. Sooner or later, though, if you want to write significant programs or scripts, you must add custom looping or branch logic to your solution. Conditional statements enable your code to branch, dependent on tests you create. Loops execute a block of code one or more times depending on ...

Get Windows PowerShell in Action, Third Edition 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.