title: Problem with switch statement in a while loop in PowerShell
body: <p>For whatever reason the While loop works by itself, the Switch statement works by itself, when I combine them.. the While loop works ok, the Switch statement though.. not so much.</p>
  
  <p>y or n are only values the While loop accepts, the problem is that when I give it y or n, none of the code gets executed, the script just finishes.</p>
  
  <p>PowerShell version is 5.1.</p>
  
  <pre><code>While (($UserInput = Read-Host -Prompt "Are you sure? (y/n)") -notmatch '^n$|^y$') {
      Switch ($UserInput) {
          'y' {
              Try {
                  Write-Output "Success."
          }
              Catch {
                  Write-Output "Error."
              }
          }
          'n' {
              Write-Output "Cancelled."
          }
      }
  }
  </code></pre>