#PSTip Getting Enum values in PowerShell 3.0

Note: This tip requires PowerShell 3.0 or above.

Prior to PowerShell 3.0, to return a list of  names or values of an Enumeration object, we needed to use the static methods of the System.Enum type:

PS> [System.Enum]::GetNames('System.ConsoleColor')
Black
DarkBlue
DarkGreen
DarkCyan
(...)

PS> [System.Enum]::GetValues('System.ConsoleColor')
Black
DarkBlue
DarkGreen
DarkCyan
(...)

PowerShell 3.0 runs on .NET 4.0 and in .NET 4.0 we can get the same information using new System.Type methods:

[System.ConsoleColor].GetEnumValues()

- or -

[System.ConsoleColor].GetEnumNames()
Share on: