Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Looping structures


PowerShell provides a variety of looping structures for evaluating and executing objects. Loops are helpful in situations where you need to take in an array of objects and process the individual values in the array. Subsequently, loops are also helpful in situations where you need to wait for a specific value within an array before proceeding in the script.

There are four main looping structures in PowerShell. These looping structures include Do/While, Do/Until, ForEach, and For. The Do/While looping structure is used to execute a task when a value doesn't equal a specific value. The inverse of this looping structure is Do/Until, where it will keep looping the structure until a value equals a specific value. ForEach is a looping structure that allows you to process each individual object in an array or set of objects. The For loop is typically used to execute a task a set number of times.

To create a new Do/While looping structure, you first start by declaring the Do command...