Enum’s numeric values


Without any loop statements or pipelines, get the numeric values of an Enum (such as IO.FileAttributes) in 1 statement.


[Enum]::GetValues('IO.FileAttributes') -as 'Long[]'

Even though the numeric values of most Enum are of Int32, or Int (PowerShell’s Int32 Type Accelerator), casting the output of Enum’s GetValues method as an Array of Int32, or Int, does not return the numeric -or integer- values. But, if the cast is to another compatible Numeric Type we get the expected output.

Winner: James Brundage

Share on:
comments powered by Disqus