An enumeration may be created without defining a value for a name. PowerShell will automatically allocate a sequence of values starting from 0. In the following example, the names Zero and One are automatically created with the values 0 and 1, respectively:
enum MyEnum {
Zero
One
}
If a value is assigned to a name, the sequence will continue from that point. The following example starts with the value 5; Six will automatically be given the value 6:
enum MyEnum {
Five = 5
Six
}
Automatic value assignment supports non-contiguous sets. The sequence may be restarted at any point, or values may be skipped. The following example demonstrates both restarting a sequence and skipping values in a sequence:
enum MyEnum {
One = 1
Two
Five = 5
Six
First = 1
Second
}
This example mixes two potentially different name sets in a single enumeration to demonstrate restarting the numeric sequence. This should be avoided outside of demonstrations as it makes the use of the enumeration ambiguous.