How it works...
As we can see, it is more efficient to write, execute, as well as troubleshoot a Switch–Case construct in such situations, rather than writing a series of If–ElseIf–ElseIf–ElseIf–...–Else statements. To define a catch-all action in Switch–Case, use Default.
The Switch–Case construct also supports wildcard (-Wildcard) and regex (-Regex). In general, it is not a good practice to omit Default unless all the possible outcomes have been covered.
The working of Switch–Case is simple: it checks the condition against all the values among the definitions, and whenever it finds a condition to be true, it executes the corresponding script block. Therefore, if three conditions among five are met, the three script blocks will be executed. ...
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.
Read now
Unlock full access