Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

Use Enum defined in classes from PowerShell

If you have an enum like this:

namespace Foo {
    public class Bar {
        public enum Baz {
            A = 0,
            B = 1,
            C = 2
        }
    }
}

You can use this enum from PowerShell with [FQCN+Enum] notation like this:

Add-Type  @"
namespace Foo {
    public class Bar {
        public enum Baz {
            A = 0,
            B = 1,
            C = 2
        }
    }
}
"@

[System.Enum]::GetNames([Foo.Bar+Baz])

$BazA = [Foo.Bar+Baz]::A
$BazA