POSH TIP: List all values belonging to an ENUM in powershell
Enum is a value type available in .NET framework. Use GetNames static method of this class to list down all values belonging to and ENUM as shown below
[Enum]::GetNames([System.Management.Automation.ActionPreference])
In the above command System.Management.Automation.ActionPreference is the Enum whose values we are interested in..
The above code return a string array and it looks like below
-
SilentlyContinue
Stop
Continue
Inquire
Ignore
Suspend
The above code can be used with an .NET Enumeration type.
Another example are below..
[Enum]::GetNames([System.Windows.Forms.MessageBoxButtons])
-
OK
OKCancel
AbortRetryIgnore
YesNoCancel
YesNo
RetryCancel
Leave a comment