Using Enumeration Types for Parameter IntelliSense

by Nov 16, 2012

In a previous tip you learned how decorating function parameters with a ValidateSet attribute would allow the ISE editor to display intelliSense help for the parameter arguments.

As an alternative, you can assign an enumeration data type to a parameter. Provided you pick the right data type, you wouldn't even have to put together the list of values:

function Select-Color
{
  param(
  [System.ConsoleColor]
  $Color
  )

  "You chose $Color"
}

Once you run this code and then in the ISE, enter this, you'll see the new argument completion in action:

Select-Color -Color <-ISE opens IntelliSense menu with color values

Twitter This Tip! ReTweet this Tip!