Param ValidateSet with spaces in values

I have written a script in which I realized that ne of the parameters may be too confusing for the end user type. So I wanted to validate the set and supply the valid values to be used. The values have spaces in them and when I validate the set I am given the choices as I would expect when running the script. But, since there are spaces in the value, the script errors out. I want to include the quotes (“some value”) in the values of the validates parameter set but cannot figure how to do it. I have tried double and single quoting. I can get the value to show up as a quoted value but then I get the error that the value supplied is not part of the set.

param [
[Validateset(‘some value’,‘Another value’,‘this is the third value’)]

This produces an unquoted value when using the script.

When I try inserting double quotes within the single quote…

param (
[Validateset(’“some value”’,’“Another value”’,’“this is the third value”’)]

I can get the quoted text to show for the script parameter but it errors out with “the argument XXXXXX does not belong to the set”

How can I get arguments with spaces to correctly show the quotes when using validateset? I have even tried escaping but cant seem to figure it out.


That’s a bit of a blind spot in PowerShell’s current tab completion logic. However, this question came up recently in another thread, and Rohn Edwards came up with a pretty cool solution: