With reflection, it is possible to create enums with values whose base type are not integral types or chars, but this is stronly discouraged.
Iterating over enumeration values in PowerShell
System.Enum
has the static method GetValues()
that returns an array of the values of a given enumeration.
The following snippets try to demonstrate how it is possible to iterate over such an array and display the values (integer and string) in
PowerShell:
PS C:\> $enumValues = [System.Enum]::GetValues('System.Environment+SpecialFolder')
PS C:\> $enumValues.GetType().FullName
System.Environment+SpecialFolder[]
PS C:\> $enumValues.length
47
PS C:\> $enumValues[0].GetType().FullName
System.Environment+SpecialFolder
PS C:\> $enumValues[42].value__
55
PS C:\> $enumValues[42].ToString()
CommonVideos
$enumValues | foreach-object {
'{0,2} {1,-30} {2}' -f $_.value__, $_.ToString(), [Environment]::GetFolderPath($_)
}
0 Desktop C:\Users\Rene\Desktop
2 Programs C:\Users\Rene\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
5 MyDocuments C:\Users\Rene\Documents
…