dharmatech
dharmatech

Reputation: 9527

ValidateSet values with spaces

Here's an example of ValidateSet where the values are strings which contain spaces:

function Test-ValidateSet
{ 
    param ([ValidateSet("abc def", "ghi jkl")][String]$Val) 

    $Val 
}

The IntelliSense works, however the completed value isn't quoted.

Is there a way to get the completed values to be quoted?

Upvotes: 4

Views: 944

Answers (2)

Rune Mariboe
Rune Mariboe

Reputation: 72

You'll have to quote yourself:

[ValidateSet("'abc def'", "'ghi jkl'")]

Though that looks silly if you intellisense after adding quotes in the command line:

Test-ValidateSet -Val ''ghi jkl''

DynamicParam doesn't work well with quoted values either.

Upvotes: 0

Related Questions