In part two of this web series about powershell classes, I would like to talk about how to use a powershell enum and go through a use case which will point out their use, and why you really want to integrate them into your scripts.

If you have missed the beginning of this blog post series, or if you are new to powershell classes, See part one here, and learn how powershell constructors and their overloads works in powershell 5 classes.

how to write a powershell enum to use in a powershell class

Since version 5 of powershell, we have the possibility to create powershell enumerations. Or more commonly called powershell enum.

What is a powershell enum? why would we even want to use a powershell enum? How do we create a powershell enum?

I’ll try to answer all of these questions in this blog post.

If you would like to see something to be covered more in depth, please let me know in the comment section below or tweet me at @stephanevg

The very basics for a powershell Enum to exist would be to having something as represented as followed:

To create a new powershell enumartion, we will use the new keyword “Enum“.

The very basics for a powershell Enum to exist would be to having something as represented as followed:

A powershell enum is used to offer a limited list of elements of a specefic type to your object.

For example, you could have a Enum called “ServerType” that would contain a list of all of your different type of servers. These are the ones that I have my lab, and which we will build the example.