I am using C# to create PowerShell cmdlets. For one of the parameters, I am using ValidateSet
.
[ValidateNotNullOrEmpty]
[ValidateSet(new string[]{"STANDARD", "CUSTOM","MINIMUM","DEFAULT"},IgnoreCase=true)]
[Parameter(
Mandatory = true,
ValueFromPipelineByPropertyName = false,
ValueFromPipeline = false,
HelpMessage = "House Mode")
]
[Alias("hm")]
public string HouseMode
{
get { return m_housemode; }
set { m_housemode = value; }
}
How can I make the value of the ValidateSet
appear in the tab-completion list?
To avoid duplication you can also encode the valid values in an enum as follows. This is how I did it in PowerShell directly, but presumably declaring an enum in your c# code would work the same e.g.:
Then declare your parameter as of that new type, viz
This gives you tab completion and if you get the value wrong the error message also lists the valid enum values, which is pretty neat.