Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
April 20, 2023

Switch Hitting with PowerShell

Last time we started diving into using the Switch construct in PowerShell scripting. I think this is an excellent alternative if you need to build a large set If/ElseIf/Else statements. That’s what I demonstrated with my menu scripts. But the Switch statement has a few other features that you can use to your advantage once you know them. Technically, you could create an If/ElseIf/Else statement to achieve the same results, but I think it would be much more complicated than using the Switch. Let’s have some fun.

Matching Options

The key concept in the Switch statement is matching. For the most part, if you are matching a string, PowerShell is doing an exact match. But you can be explicit.

Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.