convert array to enum

This topic contains 3 replies, has 3 voices, and was last updated by  postanote 2 weeks, 2 days ago.

  • Author
    Posts
  • #85282

    kort3x
    Participant

    I have an array $computernames and need an enum [validComputernames]

    The solution in the thread below is not working for me and seems outdated since PS5.0 added the enum Keyword.

    Any ideas?

  • #85285

    kort3x
    Participant

    Ok, I found away using invoke-expression. Not very elegant but it works

    $computernames = Get-content C:\Paul2018\Clients.txt
    
    $exp = "Enum ValidComputernames{
        $(foreach ($name in $computernames){$name + ';'})
    }"
    
    Invoke-Expression $exp
    
  • #85294

    js
    Participant
  • #85295

    postanote
    Participant

    How is your approach different / more efficient that what is documented here:
    'social.technet.microsoft.com/wiki/contents/articles/26436.how-to-create-and-use-enums-in-powershell.aspx'

You must be logged in to reply to this topic.