11---
22description : Align assignment statement
3- ms.date : 03/20 /2026
3+ ms.date : 06/12 /2026
44ms.topic : reference
55title : AlignAssignmentStatement
66---
@@ -10,13 +10,20 @@ title: AlignAssignmentStatement
1010
1111## Description
1212
13- Consecutive assignment statements are more readable when they're aligned. Assignments are considered
14- aligned when their ` equals ` signs line up vertically.
13+ This rule detects misaligned assignment operators in hashtables and enum definitions. Consecutive
14+ assignment statements are easier to read and maintain when their assignment operators align
15+ vertically.
1516
16- This rule looks at the key-value pairs in hashtables (including DSC configurations) as well as enum
17+ This rule checks key-value pairs in hashtables and enum member definitions to ensure that the ` = `
18+ signs line up. Use this rule to enforce consistent formatting in multiline hashtables and enum
1719definitions.
1820
19- Consider the following example with a hashtable and enum that isn't aligned.
21+ The rule ignores assignments within hashtables and enums that appear on the same line as other
22+ assignments. For example, the rule ignores ` $h = @{ a = 1; b = 2 } ` .
23+
24+ ## Example
25+
26+ ### Noncompliant
2027
2128``` powershell
2229$hashtable = @{
@@ -30,7 +37,7 @@ enum Enum {
3037}
3138```
3239
33- Alignment in this case would look like the following.
40+ ### Compliant
3441
3542``` powershell
3643$hashtable = @{
@@ -44,9 +51,6 @@ enum Enum {
4451}
4552```
4653
47- The rule ignores any assignments within hashtables and enums which are on the same line as others.
48- For example, the rule ignores ` $h = @{a = 1; b = 2} ` .
49-
5054## Configuration
5155
5256``` powershell
@@ -62,22 +66,24 @@ Rules = @{
6266}
6367```
6468
65- ### Parameters
69+ ## Parameters
6670
67- #### Enable: bool (Default value is ` $false ` )
71+ ### Enable
6872
69- Enable or disable the rule during ScriptAnalyzer invocation.
73+ This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a
74+ boolean value. To enable this rule, set this parameter to ` $true ` . The default value is ` $false ` .
7075
71- #### CheckHashtable: bool (Default value is ` $true ` )
76+ ### CheckHashtable
7277
73- Enforce alignment of assignment statements in a hashtable and in a DSC Configuration. There is only
74- one setting for hashtable and DSC configuration because the property value pairs in a DSC
75- configuration are parsed as key-value pairs of a hashtable .
78+ This parameter controls whether ScriptAnalyzer checks assignment alignment in hashtables and Desired
79+ State Configuration ( DSC) configurations. It accepts a boolean value. To disable this check, set
80+ this parameter to ` $false ` . The default value is ` $true ` .
7681
77- #### AlignHashtableKvpWithInterveningComment: bool (Default value is ` $true ` )
82+ ### AlignHashtableKvpWithInterveningComment
7883
79- Include key-value pairs in the alignment that have an intervening comment - that is to say a comment
80- between the key name and the equals sign.
84+ This parameter controls whether ScriptAnalyzer includes hashtable key-value pairs that contain an
85+ intervening comment when determining alignment. It accepts a boolean value. To exclude these lines,
86+ set this parameter to ` $false ` . The default value is ` $true ` .
8187
8288Consider the following:
8389
@@ -89,7 +95,8 @@ $hashtable = @{
8995}
9096```
9197
92- With this setting disabled, the line with the comment is ignored, and it would be aligned like so:
98+ With this setting disabled, the line with the comment is ignored. The equal signs are aligned for
99+ the remaining lines:
93100
94101``` powershell
95102$hashtable = @{
@@ -99,7 +106,7 @@ $hashtable = @{
99106}
100107```
101108
102- With it enabled, the comment line is included in alignment :
109+ With this setting enabled, the equal signs are aligned for all lines :
103110
104111``` powershell
105112$hashtable = @{
@@ -109,49 +116,23 @@ $hashtable = @{
109116}
110117```
111118
112- #### CheckEnum: bool (Default value is ` $true ` )
113-
114- Enforce alignment of assignment statements of an Enum definition.
115-
116- #### AlignEnumMemberWithInterveningComment: bool (Default value is ` $true ` )
117-
118- Include enum members in the alignment that have an intervening comment - that is to say a comment
119- between the member name and the equals sign.
120-
121- Consider the following:
122-
123- ``` powershell
124- enum Enum {
125- member = 1
126- anotherMember <#A Comment#> = 2
127- anotherDifferentMember = 3
128- }
129- ```
130-
131- With this setting disabled, the line with the comment is ignored, and it would be aligned like so:
119+ ### CheckEnum
132120
133- ``` powershell
134- enum Enum {
135- member = 1
136- anotherMember <#A Comment#> = 2
137- anotherDifferentMember = 3
138- }
139- ```
121+ This parameter controls whether ScriptAnalyzer checks assignment alignment in enum member
122+ definitions. It accepts a boolean value. To disable this check, set this parameter to ` $false ` . The
123+ default value is ` $true ` .
140124
141- With it enabled, the comment line is included in alignment:
125+ ### AlignEnumMemberWithInterveningComment
142126
143- ``` powershell
144- enum Enum {
145- member = 1
146- anotherMember <#A Comment#> = 2
147- anotherDifferentMember = 3
148- }
149- ```
127+ This parameter controls whether ScriptAnalyzer includes enum members that contain an intervening
128+ comment when determining alignment. It accepts a boolean value. To exclude these lines, set this
129+ parameter to ` $false ` . The default value is ` $true ` .
150130
151- #### IncludeValuelessEnumMembers: bool (Default value is ` $true ` )
131+ ### IncludeValuelessEnumMembers
152132
153- Include enum members in the alignment that don't have an explicitly assigned value. Enums don't
154- need to be given a value when they're defined.
133+ This parameter controls whether ScriptAnalyzer includes enum members without explicitly assigned
134+ values when determining alignment. It accepts a boolean value. To exclude valueless members, set
135+ this parameter to ` $false ` . The default value is ` $true ` .
155136
156137Consider the following:
157138
@@ -164,7 +145,7 @@ enum Enum {
164145```
165146
166147With this setting disabled, the third line, which has no value, isn't considered when choosing where
167- to align assignments. It would be aligned like so:
148+ to align assignments.
168149
169150``` powershell
170151enum Enum {
0 commit comments