Skip to content

Commit 54055c0

Browse files
committed
Sync docs updates to source repo
1 parent 4b0117c commit 54055c0

76 files changed

Lines changed: 1926 additions & 1705 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/Rules/AlignAssignmentStatement.md

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Align assignment statement
3-
ms.date: 03/20/2026
3+
ms.date: 06/12/2026
44
ms.topic: reference
55
title: 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
1719
definitions.
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

8288
Consider 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

156137
Consider the following:
157138

@@ -164,7 +145,7 @@ enum Enum {
164145
```
165146

166147
With 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
170151
enum Enum {

docs/Rules/AvoidAssignmentToAutomaticVariable.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Changing automatic variables might have undesired side effects
3-
ms.date: 06/28/2023
3+
ms.date: 06/12/2026
44
ms.topic: reference
55
title: AvoidAssignmentToAutomaticVariable
66
---
@@ -10,11 +10,15 @@ title: AvoidAssignmentToAutomaticVariable
1010

1111
## Description
1212

13-
PowerShell has built-in variables known as automatic variables. Many of them are read-only and
14-
PowerShell throws an error when trying to assign an value on those. Other automatic variables should
15-
only be assigned in certain special cases to achieve a certain effect as a special technique.
13+
This rule detects assignments to automatic variables and parameter names that use automatic variable
14+
names. PowerShell automatically defines variables that store internal state information and manages
15+
them on its own. Even though you _can_ override many automatic variables, doing so can have
16+
unexpected effects for users and make your code harder to maintain and debug.
1617

17-
To understand more about automatic variables, see `Get-Help about_Automatic_Variables`.
18+
Avoid using automatic variable names in your functions and parameters. Reserve automatic variables
19+
for PowerShell's internal use only, and rely on them only to read state information.
20+
21+
To learn more, see [about_Automatic_Variables][01].
1822

1923
<!-- TODO
2024
Ability to suppress was added in https://github.com/PowerShell/PSScriptAnalyzer/pull/1896
@@ -27,9 +31,9 @@ Use variable names in functions or their parameters that do not conflict with au
2731

2832
## Example
2933

30-
### Wrong
34+
### Noncompliant
3135

32-
The variable `$Error` is an automatic variables that exists in the global scope and should therefore
36+
The variable `$Error` is an automatic variable that exists in the global scope and should therefore
3337
never be used as a variable or parameter name.
3438

3539
```powershell
@@ -40,8 +44,12 @@ function foo($Error){ }
4044
function Get-CustomErrorMessage($ErrorMessage){ $Error = "Error occurred: $ErrorMessage" }
4145
```
4246

43-
### Correct
47+
### Compliant
4448

4549
```powershell
4650
function Get-CustomErrorMessage($ErrorMessage){ $FinalErrorMessage = "Error occurred: $ErrorMessage" }
4751
```
52+
53+
<!-- Link reference definitions -->
54+
55+
[01]: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_automatic_variables

docs/Rules/AvoidDefaultValueForMandatoryParameter.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Avoid Default Value For Mandatory Parameter
3-
ms.date: 06/28/2023
3+
ms.date: 06/12/2026
44
ms.topic: reference
55
title: AvoidDefaultValueForMandatoryParameter
66
---
@@ -10,13 +10,14 @@ title: AvoidDefaultValueForMandatoryParameter
1010

1111
## Description
1212

13-
Mandatory parameters should not have a default values because there is no scenario where the default
14-
can be used. PowerShell prompts for a value if the parameter value is not specified when calling the
15-
function.
13+
This rule detects when mandatory parameters have default values assigned. Mandatory parameters
14+
shouldn't have default values because they can't be used. When a parameter is marked as mandatory,
15+
PowerShell always prompts the user for a value if one isn't supplied when calling the function. Any
16+
default value assigned to a mandatory parameter is unreachable and serves no purpose.
1617

1718
## Example
1819

19-
### Wrong
20+
### Noncompliant
2021

2122
```powershell
2223
function Test
@@ -31,7 +32,7 @@ function Test
3132
}
3233
```
3334

34-
### Correct
35+
### Compliant
3536

3637
```powershell
3738
function Test

docs/Rules/AvoidDefaultValueSwitchParameter.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: Switch Parameters Should Not Default To True
3-
ms.date: 12/05/2024
2+
description: Switch parameters should not default to $true
3+
ms.date: 06/12/2026
44
ms.topic: reference
55
title: AvoidDefaultValueSwitchParameter
66
---
@@ -10,23 +10,24 @@ title: AvoidDefaultValueSwitchParameter
1010

1111
## Description
1212

13-
If your parameter takes only `true` and `false`, define the parameter as type `[Switch]`. PowerShell
14-
treats a switch parameter as `true` when it's used with a command. If the parameter isn't included
15-
with the command, PowerShell considers the parameter to be false. Don't define `[Boolean]`
16-
parameters.
13+
This rule detects switch parameters that are assigned a default value of `$true`. Switch parameters
14+
shouldn't have default values. By design, a switch parameter is `$false` when not specified and
15+
`$true` when included in the command. Assigning a default value of `$true` to a switch parameter
16+
violates this design principle and can cause unexpected behavior.
1717

18-
You shouldn't define a switch parameter with a default value of `$true` because this isn't the
19-
expected behavior of a switch parameter.
18+
If your parameter needs to accept only `true` and `false` values, use the `[Switch]` type instead of
19+
`[Boolean]`. PowerShell automatically handles switch parameters correctly without requiring a
20+
default value.
2021

21-
## How
22+
To fix this issue, remove the default value from the switch parameter declaration. The switch
23+
naturally defaults to `$false` when not specified, allowing your logic to respond appropriately to
24+
the caller's input.
2225

23-
Change the default value of the switch parameter to be `$false` or don't provide a default value.
24-
Write the logic of the script to assume that the switch parameter default value is `$false` or not
25-
provided.
26+
To learn more, see [Strongly Encouraged Development Guidelines][01].
2627

2728
## Example
2829

29-
### Wrong
30+
### Noncompliant
3031

3132
```powershell
3233
function Test-Script
@@ -44,7 +45,7 @@ function Test-Script
4445
}
4546
```
4647

47-
### Correct
48+
### Compliant
4849

4950
```powershell
5051
function Test-Script
@@ -69,9 +70,5 @@ function Test-Script
6970
}
7071
```
7172

72-
## More information
73-
74-
- [Strongly Encouraged Development Guidelines][01]
75-
7673
<!-- link references -->
7774
[01]: https://learn.microsoft.com/powershell/scripting/developer/cmdlet/strongly-encouraged-development-guidelines#parameters-that-take-true-and-false

docs/Rules/AvoidExclaimOperator.md

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Avoid exclaim operator
3-
ms.date: 03/26/2024
3+
ms.date: 05/28/2026
44
ms.topic: reference
55
title: AvoidExclaimOperator
66
---
@@ -10,39 +10,32 @@ title: AvoidExclaimOperator
1010

1111
## Description
1212

13-
Avoid using the negation operator (`!`). Use `-not` for improved readability.
13+
This rule detects the use of the negation operator (an exclamation mark, `!`) and recommends using
14+
the `-not` operator instead for improved readability and consistency with PowerShell conventions.
1415

15-
> [!NOTE]
16-
> This rule is not enabled by default. The user needs to enable it through settings.
16+
The `-not` operator is more explicit and aligns with PowerShell's verbose style, making code
17+
easier to understand at a glance.
1718

18-
## How to Fix
19+
This rule is **disabled** by default. Enable it explicitly during ScriptAnalyzer invocation if
20+
desired.
1921

2022
## Example
2123

22-
### Wrong
24+
### Noncompliant
2325

2426
```powershell
2527
$MyVar = !$true
2628
```
2729

28-
### Correct
30+
### Compliant
2931

3032
```powershell
3133
$MyVar = -not $true
3234
```
3335

34-
## Configuration
36+
## Parameters
3537

36-
```powershell
37-
Rules = @{
38-
PSAvoidExclaimOperator = @{
39-
Enable = $true
40-
}
41-
}
42-
```
43-
44-
### Parameters
45-
46-
- `Enable`: **bool** (Default value is `$false`)
38+
### Enable
4739

48-
Enable or disable the rule during ScriptAnalyzer invocation.
40+
This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a
41+
boolean value. To enable this rule, set this parameter to `$true`. The default value is `$false`.

0 commit comments

Comments
 (0)