The code below allows creation of .NET enumerations in PowerShell without using Add-Type.

Before an Enum is created a Dynamic Assembly and Module is created to hold it. The function below does that and, by default, leaves the module in a global variable called Indented_ModuleBuilder. Attempting to retrieve the module builder dynamically returns an InternalModuleBuilder class which cannot be used later (at least not as I wish).

Once the dynamic module is created, any number of Enums can be created from hash tables.

The last example below shows how the functions can be used once they have been loaded.

Leave a Reply

Your email address will not be published. Required fields are marked *