New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about_Switch requires fixes and improvements #3512

mklement0 opened this Issue Jan 7, 2019 · 0 comments


None yet
2 participants
Copy link

mklement0 commented Jan 7, 2019

Required fixes:

Use of an expression vs. a script block as a branch condition:

If the condition is an expression or a script block, it is evaluated just before it is compared to the value. The value is assigned to the $_ automatic variable and is available in the expression. The match succeeds if the expression is true or matches the value. The expression is evaluated in its own scope.

Use of an expression vs. use of a script block are distinct use cases that must be documented separately:

  • $_ is only available in a script block, and running it is own scope also only applies to use of a script block.

  • While an expression's result must match the input the input value, a script block is expected to return a Boolean - see PowerShell/PowerShell#8591

The precedence rules if conflicting options such as -wildcard and -regex are combined are incorrect; e.g.:

If you use Wildcard, Regex and Exact are ignored

In reality, whatever option is specified last wins, and any conflicting ones are ignored.

Note the related proposal to prevent conflicts to begin with during parsing: PowerShell/PowerShell#8598


-exact should be documented as an option, explicit way to opt into the default behavior that is never needed; see PowerShell/PowerShell#8599

Version(s) of document impacted

  • Impacts document
  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment