PowerTip: View All Values of an Enum


Summary: Boe Prox shows how to view all values of an enum.

Hey, Scripting Guy! Question How can I view all of the available values of an enum?

Hey, Scripting Guy! Answer Use the [Enum]::GetNames() method, for example:

PS C: > [Enum]::GetNames([System.ConsoleColor])

Black

DarkBlue

DarkGreen

DarkCyan

DarkRed

DarkMagenta

DarkYellow

Gray

DarkGray

Blue

Green

Cyan

Red

Magenta

Yellow

White

Comments (4)

  1. JV says:

    We can also do this:

    [System.ConsoleColor]::GetNames([System.ConsoleColor])

    We can do this:
    add-type -AssemblyName presentationframework
    [System.Windows.SystemColors]
    [System.ConsoleColor]::DarkCyan
    … etc …

    So why can’t we do this?

    [Enum]::GetNames([System.Windows.SystemColors])

  2. OldFart says:

    @JV: Because System.Windows.SystemColors is not an enum.

  3. Comfortably eNum says:

    PowerShell ISE Add-On to generate a PowerShell switch source code template for an enum. The module provides two PowerShell GUI Forms for inputting and selecting an enum.

    http://gallery.technet.microsoft.com/PowerShell-Add-On-to-15266a71#content

Skip to main content