From the course: PowerShell 7 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Switch statements

Switch statements - PowerShell Tutorial

From the course: PowerShell 7 Essential Training

Start my 1-month free trial

Switch statements

- [Instructor] Now, there is another mechanism available to us. I'm just going to make some more space here, and we'll clear the bottom. The other option that will help us in flowing specific things, is what's referred to as a Switch Statement. Now, a switch statement allows me to say, pass a value into it, and the switch statement then determines what to do. So let me give you an idea of how this works. So, first off, I'm going to type in here. So this is value. I'm going to say, "Type your favorite car brand," and then we're going to check the value. Now, to validate the value that's been typed in, we're going to utilize a switch command. Now, I'm going to copy from the exercise file into here, just make it easier. So, I'm going to paste it in and you can see that it says, "Switch value", and then we have "Brand1, Brand2, Brand3, Brand4." Those are the values that the switch command is expecting. So let's select…

Contents