Function with Enum values for ValidateSet parameter

This topic contains 1 reply, has 1 voice, and was last updated by  Michael 2 weeks, 4 days ago.

  • Author
    Posts
  • #90883

    Michael
    Participant

    Hey all,

    I built an enum with a lot of values with hopes that I could use the values of the enum within a [ValidateSet([EnumName])], but it doesn't work. If I do the following below, the Enum values are available, but if I use multiple values like such Get-Something -Value v1,v2,v3 the right values do not get passed into the function.

    If I only pass in 1 value "Get-something -value v1" then the function works correctly.

    What am I missing?

    function Get-Something {
      [CmdletBinding()]
      param(
        [EnumName]
        [String[]]
        $Value  
      )
    }
    

    Thanks,
    Michael

  • #90889

    Michael
    Participant

    I figured it out. Add the [] within the EnumName type for the param. 😀

    function Get-Something {
      [CmdletBinding()]
      param(
        [EnumName[]]
        $Value  
      )
    }
    

You must be logged in to reply to this topic.