title: Powershell: multi-parameters validation
body: <p>I've a <strong>Powershell</strong> function as follows:</p>
  
  <pre><code>function myfunct {
  
      param(
          [Parameter(ParameterSetName="p1")]
          [string] $p1,
          [Parameter(ParameterSetName="p21")]
          [string] $p21,
          [Parameter(ParameterSetName="p22")]
          [string] $p22
      )
  
      # ...
  
  }
  </code></pre>
  
  <p>This script accepts two configurations of parameters:</p>
  
  <ol>
  <li><p>By specifying the value of <code>p1</code> : <code>p1 and [not (p21 and p22)]</code></p></li>
  <li><p>By specifying the value of <code>p21</code> and <code>p22</code> : <code>(not p1) and (p21 and p22)</code></p></li>
  </ol>
  
  <p>Now, I would like to check their mutual exclusivity. By reading the article <strong><a href="http://blogs.msdn.com/b/powershell/archive/2008/12/23/powershell-v2-parametersets.aspx" rel="nofollow">PowerShell V2: ParameterSets</a></strong> on MSDN, I found an example about how to properly use the value of <code>$PsCmdlet.ParameterSetName</code> in order to check the specified parameter:</p>
  
  <pre><code>function test-param 
  { 
  param( 
  [Parameter(ParameterSetName="p1",Position=0)] 
  [DateTime] 
  $d, 
  
  [Parameter(ParameterSetName="p2", Position=0)] 
  [int] 
  $i 
  ) 
      switch ($PsCmdlet.ParameterSetName) 
      { 
      "p1"  { Write-Host $d; break} 
      "p2"  { Write-Host $i; break} 
      } 
  }
  </code></pre>
  
  <p>According to the the example above, <code>$PsCmdlet.ParameterSetName</code> returns the value of a single parameter, but in my second configuration I need to know if <code>p21</code> and <code>p22</code> have been inserted (and if <code>p1</code> is empty, of course).</p>
  
  <p>Is there a way to perform the parameter validation as desired? If yes, how?</p>