Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could group those parameters by defining a parameter set to accomplish this.</p> <pre class="lang-powershell prettyprint-override"><code>param ( [Parameter(ParameterSetName='One')][switch]$CreateNewChild, [Parameter(ParameterSetName='One',Mandatory=$true)][string]$PropertyType ) </code></pre> <p>Reference: </p> <p><a href="http://blogs.msdn.com/b/powershell/archive/2008/12/23/powershell-v2-parametersets.aspx" rel="noreferrer">http://blogs.msdn.com/b/powershell/archive/2008/12/23/powershell-v2-parametersets.aspx</a></p> <p><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/30/use-parameter-sets-to-simplify-powershell-commands.aspx" rel="noreferrer">http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/30/use-parameter-sets-to-simplify-powershell-commands.aspx</a></p> <p>--- Update ---</p> <p>Here's a snippet that mimics the functionality you're looking for. The "Extra" parameter set will not be processed unless the -Favorite switch is called.</p> <pre class="lang-powershell prettyprint-override"><code>[CmdletBinding(DefaultParametersetName='None')] param( [Parameter(Position=0,Mandatory=$true)] [string]$Age, [Parameter(Position=1,Mandatory=$true)] [string]$Sex, [Parameter(Position=2,Mandatory=$true)] [string]$Location, [Parameter(ParameterSetName='Extra',Mandatory=$false)][switch]$Favorite, [Parameter(ParameterSetName='Extra',Mandatory=$true)][string]$FavoriteCar ) $ParamSetName = $PsCmdLet.ParameterSetName Write-Output "Age: $age" Write-Output "Sex: $sex" Write-Output "Location: $Location" Write-Output "Favorite: $Favorite" Write-Output "Favorite Car: $FavoriteCar" Write-Output "ParamSetName: $ParamSetName" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload