title: How to mark a switch parameter as mandatory in Powershell
body: <p>I'm pretty sure I don't have any other options other than what I've uncovered, but I wanted to pick the collective internet brain.</p>
  
  <p>I prefer to use a <strong>[switch]</strong> parameter when passing boolean values to custom functions. However, I have a few cases in which I wanted to mark the switch parameter as mandatory. This can optionally be accomplished through <strong>[parameter(Mandatory = $true)]</strong> on the parameter. However, I really dislike the UI prompt that shows up. I much prefer throwing an exception.</p>
  
  <p>But, a switch can be either true or false, and the "IsPresent" property makes no distinction. If I pass a switch parameter as <strong>-example:$false</strong>, the switch reports that <em>$example.IsPresent is false</em>!</p>
  
  <p>I have resorted to using a [bool]. For example:</p>
  
  <pre><code>param
  (
     [bool]$theValue = $(throw('You didn't specify the value!'))
  );
  </code></pre>
  
  <p>Are there any other tricks I can pull?</p>