Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

parameter sets - getting the ambigous error but don't know why

$
0
0

Hello,

Example parameter declaration:

param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] [string[]] $criteria, [Parameter(Mandatory=$true, ParameterSetName="ByIP")] [switch] $IP = $false, [Parameter(Mandatory=$true, ParameterSetName="ByDomainName")] [switch] $DomainName = $false, [Parameter(Mandatory=$true, ParameterSetName="ByClientID")] [switch] $ClientID = $false, [Parameter(Mandatory=$true, ParameterSetName="ByClientSysID")] [switch] $ClientSysID = $false, [Parameter(Mandatory=$true, ParameterSetName="ByDeviceID")] [switch] $DeviceID = $false, [Parameter(Mandatory=$true, ParameterSetName="ByDeviceSysID")] [switch] $DeviceSysID = $false, [switch] $IncludeDeleted = $false, [switch] $IncludeRestricted = $true )

As I understand it, in my declaration above, the first and last two parameters should belong to ALL parameter sets since there is no name specified. All those other switch params (ParameterSetNames starting with "By") should be optional. This is for a function that performs a search, the desired behavior is that you should be able to do any of the following:

The-Function searchtext
The-Function searchtext -IncludeDeleted
The-Function searchtext -IncludeDeleted -IncludeRestricted
The-Function searchtext -IP
The-Function searchtext -DomainName
The-Function searchtext -DomainName -IncludeDeleted
...

etc.. basically "DomainName or any of those other "By" params... those switches tell the search function to only check a particular database field rather than a standard search that would be checking multiple fields. If none are supplied it does a standard search, if one of them is supplied, it searches only that field.

I've tried without the mandatory=true, still doesn't work, I started that way but found out I needed to use that to make those mutually exclusive.. except for the first, and last two params, all those others switch params need to be mutually exclusive.

however I get the 'AmbiguousParameterSet' error if I don't use one of those "By" switches?



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>