title: Is there a better way to declare multiple parameter sets?
body: <p>I'm writing a cmdlet (in PowerShell) that is responsible for writing a record into a database. With the conditional command line, it seems like I have to define four different parameter sets.</p>
  
  <p>Is there a more succient way of doing this?</p>
  
  <p><em>DETAILS</em></p>
  
  <p>The parameters of the cmdlet are:</p>
  
  <ul>
  <li><code>ComputerName</code> (the SQL server to connect to)</li>
  <li><code>Path</code> (the location of the data)</li>
  <li><code>Xml</code> (the raw data itself)</li>
  <li><code>UserName</code></li>
  <li><code>Password</code> </li>
  <li><code>UseIntegratedSecurity</code> (instead of username/password, use current credentials)</li>
  </ul>
  
  <p><code>Path</code> and <code>Xml</code> are mutually exclusive, and <code>UserName</code>/<code>Password</code> and <code>UseIntegratedSecurity</code> are mutually exclusive.</p>
  
  <p>To get this wired up correctly, it seems like I have to define four different parameter sets, e.g.:</p>
  
  <pre><code>
  function Install-WidgetData
  {
      [CmdletBinding()]
      PARAM
      (
          [Parameter(ParameterSetName="Xml_AutoConnect", Mandatory=$True)]
          [Parameter(ParameterSetName="Xml_ManualConnect", Mandatory=$True)]
          [Parameter(ParameterSetName="Path_AutoConnect", Mandatory=$True, )]
          [Parameter(ParameterSetName="Path_ManualConnect", Mandatory=$True)]
          [ValidateNotNullOrEmpty()]
          [string[]] $ComputerName,
  
          [Parameter(ParameterSetName="Path_AutoConnect", Mandatory=$True)]
          [Parameter(ParameterSetName="Path_ManualConnect", Mandatory=$True)]
          [ValidateNotNullOrEmpty()]
          [string] $Path,
  
          [Parameter(ParameterSetName="Xml_AutoConnect", Mandatory=$True)]
          [Parameter(ParameterSetName="Xml_ManualConnect", Mandatory=$True)]
          [ValidateNotNullOrEmpty()]
          [string[]] $Xml,
  
          [Parameter(ParameterSetName="Xml_AutoConnect")]
          [Parameter(ParameterSetName="Path_AutoConnect")]
          [switch] $UseIntegratedSecurity,
  
          [Parameter(ParameterSetName="Xml_ManualConnect")]
          [Parameter(ParameterSetName="Path_ManualConnect")]
          [ValidateNotNullOrEmpty()]
          [string] $UserName,
  
          [Parameter(ParameterSetName="Xml_ManualConnect")]
          [Parameter(ParameterSetName="Path_ManualConnect")]
          [ValidateNotNullOrEmpty()]
          [string] $Password,
      )
  </code></pre>