4

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?

dharmatech
  • 8,979
  • 8
  • 42
  • 88
  • Does this answer your question? [PowerShell Param ValidateSet values with Spaces and Tab completion](https://stackoverflow.com/questions/30633098/powershell-param-validateset-values-with-spaces-and-tab-completion) – stackprotector Aug 31 '23 at 07:22

2 Answers2

3

It looks like a bug in PowerShell. I've filed it here: https://connect.microsoft.com/PowerShell/feedback/details/812233/auto-completed-values-with-spaces-do-not-have-quotes-around-them

0

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.