Enumerations
An enumeration is a specialized type that is used to express a list of constants. Enumerations are used throughout .NET and PowerShell.
PowerShell itself makes use of enumerations for many purposes. For example, the possible values for the $VerbosePreference
variable are described in an enumeration:
PS> $VerbosePreference.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ActionPreference System.Enum
Notice that the BaseType
is System.Enum
, indicating that this type is an enumeration.
The possible values for an enumeration can be listed in several different ways. The most convenient of these is to use the GetEnumValues()
method on the enumeration type:
PS> $VerbosePreference.GetType().GetEnumValues()
SilentlyContinue
Stop
Continue
Inquire
Ignore
Suspend
Break
Enumerations are relatively simple types. They...