Reputation: 751
I have developed a custom c# cmdlet. It has three parameters (all of them are strings) and none of them are mandatory. Two of them belong to parameterset1 and the third belongs to parameterset2. It is working fine, when a user gives parameters from both the parameter sets then it gives message that they do not belong to same parameter set. But I'm getting two problems:
Here is the code how I defined the parameters:
[System.Management.Automation.Cmdlet(System.Management.Automation.VerbsCommon.Get, "Customcmd")]
public class Get_Customcmd: System.Management.Automation.PSCmdlet
{
[System.Management.Automation.Parameter(Mandatory = false, ParameterSetName = "Set1")]
public string Param1;
[System.Management.Automation.Parameter(Mandatory = false, ParameterSetName = "Set1")]
public string Param2;
[System.Management.Automation.Parameter(Mandatory = false, ParameterSetName = "Set2")]
public string Param2;
protected override void ProcessRecord()
{
Can anyone tell me did I miss anything? Should add anymore attributes to the parameters?
Upvotes: 1
Views: 1315
Reputation: 1060
Since you are using only named parameters, you need to either mark one of them as 'DefaultParameterSet' like[Cmdlet(VerbsCommon.New, "Customcmd", DefaultParameterSetName = Set1)]
or have at least one parameter which is not a part of any named ParameterSet.
PS doesn't check whether the tab suggestions belong to same parameter set or not. So you are not doing anything wrong here, thats the way PS behaves.
Upvotes: 1