The switch construct is somewhat similar to an F construct that has multiple allusive sections.
The switch construct accepts a single value or a variable that contains a value or a property that contains
a value.
It compares that value to one of several possibilities that you provide when it finds a match.
It executes the corresponding script block.
A default section will execute only if no other matches were made.
For example.
Dollar drive equals get see I am instance class name when 32 underscore logical disk filter device id
equal c switch dollar drive dot drive type.
Three rate fixed local.
Five.
Right.
Optical.
Default write other.
The switch construct can also match by using wildcard patterns, regular expressions and so on.
To do this, you must specify a parameter that tells the construct what kind of match you want.
For information about the available options, run help about underscore switch in Windows PowerShell.
The construct differs from if in one important way.
It will execute each matching script block instead of executing only the first matching condition.
For example, dollar name equals get content EMV backslash computer name switch wild card dollar name
law underscore ACL one asterisk.
Right.
Computer is a client lol.
An asterisk.
Right.
Computer is in low end.
Asterisk.
DC Asterisk.
Right.
Computer is a DC.
Asterisk one.
Right.
Computer is the first one default.
Right.
No matches.
In this example, ELO and Ciel one will display both computer is a client and computer is the first
one because both conditions match.
You can use the break keyword to exit the construct.
This prevents multiple matches, for example.
Dollar name equals get content EMV backslash computer name switch wild card dollar name loan underscore
seal one asterisk.
Right computer is a client Drake.
LOL.
An asterisk.
Right.
Computer is in NYC.
Asterisk.
DC Asterisk.
Right.
Computer is a DC Drake.
Asterisk one.
Right.
Computer is the first one default.
Right.
No matches.
L0 and l one will now display only computer is a client.
The computer elo and DC one would display computer is in NYC and computer is a DC.