Function with Enum values for ValidateSet parameter

Welcome Forums General PowerShell Q&A Function with Enum values for ValidateSet parameter

This topic contains 1 reply, has 1 voice, and was last updated by

 
Participant
10 months, 1 week ago.

  • Author
    Posts
  • #90883

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

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

The topic ‘Function with Enum values for ValidateSet parameter’ is closed to new replies.