-
Notifications
You must be signed in to change notification settings - Fork 29
/
Get-EnumValues.ps1
123 lines (113 loc) · 2.7 KB
/
Get-EnumValues.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
.SYNOPSIS
Returns the possible values of the specified enumeration.
.INPUTS
System.Type of an Enum to get the values for.
.OUTPUTS
System.Management.Automation.PSCustomObject with the Value and Name for each defined
value of the Enum.
.FUNCTIONALITY
PowerShell
.EXAMPLE
Get-EnumValues Management.Automation.ActionPreference
|Value Name
|----- ----
| 0 SilentlyContinue
| 1 Stop
| 2 Continue
| 3 Inquire
| 4 Ignore
| 5 Suspend
.EXAMPLE
Get-EnumValues ConsoleColor
|Value Name
|----- ----
| 0 Black
| 1 DarkBlue
| 2 DarkGreen
| 3 DarkCyan
| 4 DarkRed
| 5 DarkMagenta
| 6 DarkYellow
| 7 Gray
| 8 DarkGray
| 9 Blue
| 10 Green
| 11 Cyan
| 12 Red
| 13 Magenta
| 14 Yellow
| 15 White
.EXAMPLE
Get-EnumValues.ps1 System.Web.Security.AntiXss.MidCodeCharts
| Value Name
| ----- ----
| 0 None
| 1 GreekExtended
| 2 GeneralPunctuation
| 4 SuperscriptsAndSubscripts
| 8 CurrencySymbols
| 16 CombiningDiacriticalMarksForSymbols
| 32 LetterlikeSymbols
| 64 NumberForms
| 128 Arrows
| 256 MathematicalOperators
| 512 MiscellaneousTechnical
| 1024 ControlPictures
| 2048 OpticalCharacterRecognition
| 4096 EnclosedAlphanumerics
| 8192 BoxDrawing
| 16384 EthiopicExtended
| 16384 EthiopicExtended
| 32768 GeometricShapes
| 65536 MiscellaneousSymbols
| 131072 Dingbats
| 262144 MiscellaneousMathematicalSymbolsA
| 524288 SupplementalArrowsA
| 1048576 BraillePatterns
| 2097152 SupplementalArrowsB
| 4194304 MiscellaneousMathematicalSymbolsB
| 8388608 SupplementalMathematicalOperators
| 16777216 MiscellaneousSymbolsAndArrows
| 33554432 Glagolitic
| 67108864 LatinExtendedC
|134217728 Coptic
|268435456 GeorgianSupplement
|536870912 Tifinagh
#>
#Requires -Version 3
[CmdletBinding()][OutputType([Management.Automation.PSCustomObject])] Param(
# The enumeration type name.
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][Type]$Type
)
Process
{
$description = @{}
$names = [enum]::GetNames($Type)
foreach($name in $names)
{
$Type.GetMember($name)[0].GetCustomAttributes([ComponentModel.DescriptionAttribute], $false) |
ForEach-Object {$description[$name] = $_.Description}
}
if($description.Values |Where-Object {$_})
{
foreach($name in $names)
{
[pscustomobject]@{
Value = [int][enum]::Parse($Type,$name)
Name = $name
Description = $description[$name]
}
}
}
else
{
foreach($name in $names)
{
[pscustomobject]@{
Value = [int][enum]::Parse($Type,$name)
Name = $name
}
}
}
}