Author Posts

November 30, 2017 at 5:53 pm

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.

Create Enum from Array

Any ideas?

November 30, 2017 at 6:35 pm

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

December 1, 2017 at 2:01 am

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'