Skip to content

Commit f4f3507

Browse files
authored
Document valid label formats (#12302)
1 parent 421ae20 commit f4f3507

File tree

4 files changed

+153
-129
lines changed

4 files changed

+153
-129
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Enum.md

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: The `enum` statement is used to declare an enumeration. An enumeration is a distinct type that consists of a set of named labels called the enumerator list.
33
Locale: en-US
4-
ms.date: 11/20/2023
4+
ms.date: 08/20/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_enum?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Enum
@@ -21,45 +21,51 @@ can use that enumeration in the code without having to parse or check for
2121
spelling errors.
2222

2323
Enumerations are internally represented as integral value types with a starting
24-
value of zero. PowerShell enumerations use **System.Int32** (`[int]`) as the
25-
underlying type. By default, PowerShell assigns the first label in the list the
26-
value zero. By default, PowerShell assigns the remaining labels with
27-
consecutive integers.
24+
value of zero. By default, PowerShell enumerations use **System.Int32**
25+
(`[int]`) as the underlying type. By default, PowerShell assigns the first
26+
label in the list the value zero. By default, PowerShell assigns the remaining
27+
labels with consecutive integers.
28+
29+
## Syntax
2830

2931
In the definition, you can give labels any integer value. Labels with no value
3032
assigned take the next integer value.
3133

32-
## Syntax
34+
Enum labels can only contain letters, underscores and digits, but must not
35+
start with a digit. The label can't be a quoted string; it must parse as a
36+
bareword string. Labels are parsed as strings not keywords. Therefore, it's
37+
possible to create a label that's the same name as a language keyword (such as
38+
`return`).
3339

3440
Enumerations use the following syntaxes:
3541

36-
### Integer enumeration definition syntax
37-
38-
```Syntax
39-
[[<attribute>]...] enum <enum-name> {
40-
<label> [= <int-value>]
41-
...
42-
}
43-
```
44-
45-
### Flag enumeration definition syntax
42+
- Integer enumeration definition syntax
4643

47-
```Syntax
48-
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
49-
<label 0> [= 1]
50-
<label 1> [= 2]
51-
<label 2> [= 4]
52-
<label 3> [= 8]
53-
...
54-
...
55-
}
56-
```
44+
```Syntax
45+
[[<attribute>]...] enum <enum-name> {
46+
<label> [= <int-value>]
47+
...
48+
}
49+
```
50+
51+
- Flag enumeration definition syntax
52+
53+
```Syntax
54+
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
55+
<label 0> [= 1]
56+
<label 1> [= 2]
57+
<label 2> [= 4]
58+
<label 3> [= 8]
59+
...
60+
...
61+
}
62+
```
5763

58-
### Enumeration access syntax
64+
- Enumeration access syntax
5965

60-
```Syntax
61-
[<enum-name>]::<label>
62-
```
66+
```Syntax
67+
[<enum-name>]::<label>
68+
```
6369

6470
## Examples
6571

reference/7.4/Microsoft.PowerShell.Core/About/about_Enum.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: The `enum` statement is used to declare an enumeration. An enumeration is a distinct type that consists of a set of named labels called the enumerator list.
33
Locale: en-US
4-
ms.date: 11/20/2023
4+
ms.date: 08/20/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_enum?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Enum
@@ -26,49 +26,55 @@ value of zero. By default, PowerShell enumerations use **System.Int32**
2626
label in the list the value zero. By default, PowerShell assigns the remaining
2727
labels with consecutive integers.
2828

29+
## Syntax
30+
2931
In the definition, you can give labels any integer value. Labels with no value
3032
assigned take the next integer value.
3133

32-
## Syntax
34+
Enum labels can only contain letters, underscores and digits, but must not
35+
start with a digit. The label can't be a quoted string; it must parse as a
36+
bareword string. Labels are parsed as strings not keywords. Therefore, it's
37+
possible to create a label that's the same name as a language keyword (such as
38+
`return`).
3339

3440
Enumerations use the following syntaxes:
3541

36-
### Integer enumeration definition syntax
37-
38-
```Syntax
39-
[[<attribute>]...] enum <enum-name> {
40-
<label> [= <int-value>]
41-
...
42-
}
43-
```
44-
45-
### Specific underlying type enumeration definition syntax
42+
- Integer enumeration definition syntax
4643

47-
```Syntax
48-
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
49-
<label> [= <int-value>]
50-
...
51-
}
52-
```
44+
```Syntax
45+
[[<attribute>]...] enum <enum-name> {
46+
<label> [= <int-value>]
47+
...
48+
}
49+
```
5350

54-
### Flag enumeration definition syntax
51+
- Specific underlying type enumeration definition syntax
5552

56-
```Syntax
57-
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
58-
<label 0> [= 1]
59-
<label 1> [= 2]
60-
<label 2> [= 4]
61-
<label 3> [= 8]
62-
...
63-
...
64-
}
65-
```
53+
```Syntax
54+
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
55+
<label> [= <int-value>]
56+
...
57+
}
58+
```
59+
60+
- Flag enumeration definition syntax
61+
62+
```Syntax
63+
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
64+
<label 0> [= 1]
65+
<label 1> [= 2]
66+
<label 2> [= 4]
67+
<label 3> [= 8]
68+
...
69+
...
70+
}
71+
```
6672

67-
### Enumeration access syntax
73+
- Enumeration access syntax
6874

69-
```Syntax
70-
[<enum-name>]::<label>
71-
```
75+
```Syntax
76+
[<enum-name>]::<label>
77+
```
7278

7379
## Examples
7480

reference/7.5/Microsoft.PowerShell.Core/About/about_Enum.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: The `enum` statement is used to declare an enumeration. An enumeration is a distinct type that consists of a set of named labels called the enumerator list.
33
Locale: en-US
4-
ms.date: 11/20/2023
4+
ms.date: 08/20/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_enum?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Enum
@@ -26,49 +26,55 @@ value of zero. By default, PowerShell enumerations use **System.Int32**
2626
label in the list the value zero. By default, PowerShell assigns the remaining
2727
labels with consecutive integers.
2828

29+
## Syntax
30+
2931
In the definition, you can give labels any integer value. Labels with no value
3032
assigned take the next integer value.
3133

32-
## Syntax
34+
Enum labels can only contain letters, underscores and digits, but must not
35+
start with a digit. The label can't be a quoted string; it must parse as a
36+
bareword string. Labels are parsed as strings not keywords. Therefore, it's
37+
possible to create a label that's the same name as a language keyword (such as
38+
`return`).
3339

3440
Enumerations use the following syntaxes:
3541

36-
### Integer enumeration definition syntax
37-
38-
```Syntax
39-
[[<attribute>]...] enum <enum-name> {
40-
<label> [= <int-value>]
41-
...
42-
}
43-
```
44-
45-
### Specific underlying type enumeration definition syntax
42+
- Integer enumeration definition syntax
4643

47-
```Syntax
48-
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
49-
<label> [= <int-value>]
50-
...
51-
}
52-
```
44+
```Syntax
45+
[[<attribute>]...] enum <enum-name> {
46+
<label> [= <int-value>]
47+
...
48+
}
49+
```
5350

54-
### Flag enumeration definition syntax
51+
- Specific underlying type enumeration definition syntax
5552

56-
```Syntax
57-
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
58-
<label 0> [= 1]
59-
<label 1> [= 2]
60-
<label 2> [= 4]
61-
<label 3> [= 8]
62-
...
63-
...
64-
}
65-
```
53+
```Syntax
54+
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
55+
<label> [= <int-value>]
56+
...
57+
}
58+
```
59+
60+
- Flag enumeration definition syntax
61+
62+
```Syntax
63+
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
64+
<label 0> [= 1]
65+
<label 1> [= 2]
66+
<label 2> [= 4]
67+
<label 3> [= 8]
68+
...
69+
...
70+
}
71+
```
6672

67-
### Enumeration access syntax
73+
- Enumeration access syntax
6874

69-
```Syntax
70-
[<enum-name>]::<label>
71-
```
75+
```Syntax
76+
[<enum-name>]::<label>
77+
```
7278

7379
## Examples
7480

reference/7.6/Microsoft.PowerShell.Core/About/about_Enum.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: The `enum` statement is used to declare an enumeration. An enumeration is a distinct type that consists of a set of named labels called the enumerator list.
33
Locale: en-US
4-
ms.date: 11/20/2023
4+
ms.date: 08/20/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_enum?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Enum
@@ -26,49 +26,55 @@ value of zero. By default, PowerShell enumerations use **System.Int32**
2626
label in the list the value zero. By default, PowerShell assigns the remaining
2727
labels with consecutive integers.
2828

29+
## Syntax
30+
2931
In the definition, you can give labels any integer value. Labels with no value
3032
assigned take the next integer value.
3133

32-
## Syntax
34+
Enum labels can only contain letters, underscores and digits, but must not
35+
start with a digit. The label can't be a quoted string; it must parse as a
36+
bareword string. Labels are parsed as strings not keywords. Therefore, it's
37+
possible to create a label that's the same name as a language keyword (such as
38+
`return`).
3339

3440
Enumerations use the following syntaxes:
3541

36-
### Integer enumeration definition syntax
37-
38-
```Syntax
39-
[[<attribute>]...] enum <enum-name> {
40-
<label> [= <int-value>]
41-
...
42-
}
43-
```
44-
45-
### Specific underlying type enumeration definition syntax
42+
- Integer enumeration definition syntax
4643

47-
```Syntax
48-
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
49-
<label> [= <int-value>]
50-
...
51-
}
52-
```
44+
```Syntax
45+
[[<attribute>]...] enum <enum-name> {
46+
<label> [= <int-value>]
47+
...
48+
}
49+
```
5350

54-
### Flag enumeration definition syntax
51+
- Specific underlying type enumeration definition syntax
5552

56-
```Syntax
57-
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
58-
<label 0> [= 1]
59-
<label 1> [= 2]
60-
<label 2> [= 4]
61-
<label 3> [= 8]
62-
...
63-
...
64-
}
65-
```
53+
```Syntax
54+
[[<attribute>]...] enum <enum-name> : <underlying-type-name> {
55+
<label> [= <int-value>]
56+
...
57+
}
58+
```
59+
60+
- Flag enumeration definition syntax
61+
62+
```Syntax
63+
[[<attribute>]...] [Flags()] enum <enum-name>[ : <underlying-type-name>] {
64+
<label 0> [= 1]
65+
<label 1> [= 2]
66+
<label 2> [= 4]
67+
<label 3> [= 8]
68+
...
69+
...
70+
}
71+
```
6672

67-
### Enumeration access syntax
73+
- Enumeration access syntax
6874

69-
```Syntax
70-
[<enum-name>]::<label>
71-
```
75+
```Syntax
76+
[<enum-name>]::<label>
77+
```
7278

7379
## Examples
7480

0 commit comments

Comments
 (0)