Questions tagged [validateset]

The ValidateSet attribute specifies a set of possible values for a cmdlet parameter argument. This attribute can also be used by Windows PowerShell functions.

The ValidateSet attribute specifies a set of possible values for a cmdlet parameter argument. This attribute can also be used by Windows PowerShell functions.

When this attribute is specified, the Windows PowerShell runtime determines whether the supplied argument for the cmdlet parameter matches an element in the supplied element set. The cmdlet is run only if the parameter argument matches an element in the set. If no match is found, an error is thrown by the Windows PowerShell runtime.

25 questions
1
vote
0 answers

Adding helper text to options in ValidateSet parameter attribute in Powershell v5

I'm using the [ValidateSet()] parameter attribute to validate that the input received by a user is included in the set of approved input values. However, I was wondering if there was a way of adding helper text to appear in the console when…
user2701761
1
vote
1 answer

PowerShell Splatting with ValidateSet

I cannot seem to get splatting to work when a functions parameter uses a validation set. The below example produces the following error: WhichFruit : Cannot validate argument on parameter 'fruit'. The argument "System.Collections.Hashtable"…
Shaun
  • 11
  • 1
1
vote
3 answers

Dynamic list of valid values for a PowerShell script

I have written a C# Tool where i can enter script parameters with an GUI which is generated based on the parmeter definitions of the script. Now i want to have a dropdown list which offers me a dynamically generated set of values. The informations…
kritzi
  • 29
  • 5
1
vote
2 answers

Tab-Completion for ValidateSet for Powershell Cmdlet

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, …
user1748546
  • 97
  • 2
  • 11
0
votes
1 answer

PowerShell | How to cross-reference parameters between 2 argument completers?

My PowerShell module has 2 argument completers. The 2 parameters with argument completers are related to each other in a way that by calculating the value of one of them, we can get the value of the other one. I want to use this relation to make…
0
votes
1 answer

Powershell Script prompt user for input on validate set Function Parameter

I'm guessing this is impossible, but I figured I'd ask because it would be cool if I could. I have a function, that has a validate set (so people don't screw up the input - obviously) However, prompts in a script don't seem to allow for this. I've…
Justin Beagley
  • 279
  • 2
  • 5
  • 14
0
votes
1 answer

Parameter validation

Im trying to validate a parameter called "Collect" to accept only 3 parameters (basic, medium and full) but when i asign a "valid" value to the "collect" parameter, it got a "false" return. Thats what i…
Richard
  • 63
  • 1
  • 9
0
votes
2 answers

Failed PowerShell ValidateSet -- Error Action to set variable to default?

function foo { param( [parameter(Mandatory=$true)] [ValidateSet('Test1','Test2','Test3')] [String]$ChooseOne= 'Test1', ) do xxxxxxxxxxxxxxxx { foo -ChooseOne Test9 I'm working on a powershell function with a set…
0
votes
2 answers

Truncate dataset after maximum value

I have a dataset with repeated measures over time, in which I am looking for predictors of the maximum tn value. I am not interested in measures which occur after this. The maximum values occur on different days for different patients. ID day tn …
Annemarie
  • 123
  • 1
  • 8
0
votes
1 answer

ValidateSet with 3001 elements causes long pause

Here's a simple function that uses ValidateSet: function TestLongValidateSet { param ( [ValidateSet(...)] $abc ) $abc } My version has 3001 items instead of the .... If you'd like to follow along at home, here's a…
dharmatech
  • 8,979
  • 8
  • 42
  • 88
1
2