Skip to Content
Learn PowerShell in a Month of Lunches, Fourth Edition
book

Learn PowerShell in a Month of Lunches, Fourth Edition

by Tyler Leonhardt, Travis Plunk, James Petty
May 2022
Beginner content levelBeginner
360 pages
10h 10m
English
Manning Publications
Content preview from Learn PowerShell in a Month of Lunches, Fourth Edition

23 Adding logic and loops

Looping (or going through a list of objects one at a time) is a fundamental concept in any language, and PowerShell is no exception. There will come a time when you will need to execute a block of code numerous times. PowerShell is well equipped to handle this for you.

23.1 Foreach and Foreach-Object

This section may be a bit confusing, as there is a difference between Foreach and Foreach-Object. Take a look at figure 23.1 for a visual representation of how Foreach works.

Figure 23.1 Diagram of how Foreach works

23.1.1 Foreach

Probably the most common form of looping is the Foreach command. Foreach allows you to iterate ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PowerShell for Sysadmins

PowerShell for Sysadmins

Adam Bertram

Publisher Resources

ISBN: 9781617296963Supplemental ContentPublisher SupportOtherPublisher WebsiteSupplemental ContentErrata PagePurchase Link