Reader small image

You're reading from  Mastering PowerShell Scripting - Fourth Edition

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781800206540
Edition4th Edition
Right arrow
Author (1)
Chris Dent
Chris Dent
author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent

Right arrow

Summary

This chapter explored the different conditional and looping statements available in PowerShell.

The if statement allows statements to be run when a condition is met and may be extended to test several conditions with elseif.

The switch statement has similarities with if, a comparison of one value against another. However, switch can test many individual cases expressed in a concise manner, allows more than one case to apply to a value, and can operate on an array.

Looping is a vital part of any programming language and PowerShell is no exception. The foreach loop is perhaps the most used, allowing repeated code to be enclosed and executed against several objects. The foreach loop keyword can often be replaced with the ForEach-Object command (or vice versa) depending on circumstances, but the two should not be confused.

The for loops are more complex but offer a great deal of flexibility for any operation based on a numeric sequence. The while and do loops...

lock icon
The rest of the page is locked
Previous PageNext Chapter
You have been reading a chapter from
Mastering PowerShell Scripting - Fourth Edition
Published in: Jun 2021Publisher: PacktISBN-13: 9781800206540

Author (1)

author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent