convert array to enum

Welcome Forums General PowerShell Q&A convert array to enum

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 3 months ago.

  • Author
  • #85282

    Points: 38
    Rank: Member

    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

    Points: 38
    Rank: Member

    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

    Points: 697
    Helping Hand
    Rank: Major Contributor
  • #85295

    Points: 1,071
    Helping Hand
    Rank: Community Hero

    How is your approach different / more efficient that what is documented here:

The topic ‘convert array to enum’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort