Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,37 @@ This parameter controls whether ScriptAnalyzer includes hashtable key-value pair
intervening comment when determining alignment. It accepts a boolean value. To exclude these lines,
set this parameter to `$false`. The default value is `$true`.

Consider the following:

```powershell
$hashtable = @{
property = 'value'
anotherProperty <#A Comment#> = 'another value'
anotherDifferentProperty = 'yet another value'
}
```

With this setting disabled, the line with the comment is ignored. The equal signs are aligned for
the remaining lines:

```powershell
$hashtable = @{
property = 'value'
anotherProperty <#A Comment#> = 'another value'
anotherDifferentProperty = 'yet another value'
}
```

With this setting enabled, the equal signs are aligned for all lines:

```powershell
$hashtable = @{
property = 'value'
anotherProperty <#A Comment#> = 'another value'
anotherDifferentProperty = 'yet another value'
}
```

### CheckEnum

This parameter controls whether ScriptAnalyzer checks assignment alignment in enum member
Expand All @@ -102,3 +133,34 @@ parameter to `$false`. The default value is `$true`.
This parameter controls whether ScriptAnalyzer includes enum members without explicitly assigned
values when determining alignment. It accepts a boolean value. To exclude valueless members, set
this parameter to `$false`. The default value is `$true`.

Consider the following:

```powershell
enum Enum {
member = 1
anotherMember = 2
anotherDifferentMember
}
```

With this setting disabled, the third line, which has no value, isn't considered when choosing where
to align assignments.

```powershell
enum Enum {
member = 1
anotherMember = 2
anotherDifferentMember
}
```

With it enabled, the valueless member is included in alignment as if it had a value:

```powershell
enum Enum {
member = 1
anotherMember = 2
anotherDifferentMember
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ for PowerShell's internal use only, and rely on them only to read state informat

To learn more, see [about_Automatic_Variables][01].

<!-- TODO
Ability to suppress was added in https://github.com/PowerShell/PSScriptAnalyzer/pull/1896
Need documentation for how to configure suppression of this rule.
-->

## How

Use variable names in functions or their parameters that do not conflict with automatic variables.

## Example

### Noncompliant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function Test-Script
[switch]
$Switch
)

...
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ $MyVar = !$true
$MyVar = -not $true
```

## Configure rule
## Parameters

### Enable

To enable this rule, run the following command:
This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a
boolean value. To enable this rule, set this parameter to `$true`. The default value is `$false`.

```powershell
Rules = @{
Expand All @@ -44,10 +47,3 @@ Rules = @{
}
}
```

## Parameters

### Enable

This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a
boolean value. To enable this rule, set this parameter to `$true`. The default value is `$false`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Avoid global aliases
description: Avoid global aliases.
ms.date: 05/28/2026
ms.topic: reference
title: AvoidGlobalAliases
Expand All @@ -15,9 +15,6 @@ aliases can unintentionally override existing aliases in the session, leading to
and name collisions. Name collisions make it difficult for module consumers to diagnose issues and
maintain code reliability.

This rule is not available in PowerShell version 3 or 4 because it uses the
`StaticParameterBinder.BindCommand` API.

To avoid this issue, define aliases without the **Scope** parameter, or use other appropriate scope
modifiers. To learn more, see [about_Scopes][01].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ function functionName {}
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_scopes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Avoid global variables
description: Avoid global variables.
ms.date: 06/23/2026
ms.topic: reference
title: AvoidGlobalVars
Expand Down Expand Up @@ -57,7 +57,6 @@ $var1
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_automatic_variables
[02]: /powershell/module/microsoft.powershell.core/about/about_preference_variables
[03]: /powershell/module/microsoft.powershell.core/about/about_scopes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Avoid invoking empty members
description: Avoid invoking empty members.
ms.date: 05/28/2026
ms.topic: reference
title: AvoidInvokingEmptyMembers
Expand Down Expand Up @@ -34,5 +34,4 @@ $MyString.('length')
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_operators#member-access-operator-
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ Function GoodFuncHelpMessage
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters#helpmessage-argument
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ function myFunction {
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_reserved_words
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ title: AvoidShouldContinueWithoutForce

## Description

This rule detects functions that use `ShouldContinue` without a boolean `Force` parameter. Functions
that use `ShouldContinue` should have a boolean `Force` parameter to allow users to bypass the
This rule detects functions that use `ShouldContinue` without a **Force** parameter. Functions that
use `ShouldContinue` should have a boolean `Force` parameter to allow users to bypass the
confirmation prompt.

When using `ShouldContinue` in advanced functions, call it after the
Expand Down Expand Up @@ -60,6 +60,5 @@ Function Test-ShouldContinue
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute
[02]: /powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ Get-Process `
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_parsing
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ Invoke-WebRequest foo
```

<!-- links reference -->

[01]: /powershell/module/microsoft.powershell.utility/invoke-webrequest
[02]: /powershell/module/microsoft.powershell.utility/invoke-restmethod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,5 @@ $SecureUserInput = Read-Host 'Please enter your secure code' -AsSecureString
```

<!-- links reference -->

[01]: /dotnet/api/system.security.securestring
[02]: https://www.powershellgallery.com/packages/Microsoft.PowerShell.SecretStore
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,4 @@ function Test-Script
```

<!-- link references -->

[01]: /dotnet/api/system.security.securestring
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Get-Command -Noun ChildItem -Module Microsoft.PowerShell.Management
Rules = @{
PSAvoidUsingPositionalParameters = @{
CommandAllowList = 'Join-Path', 'MyCmdletOrScript'
Enable = $true
Enable = $true
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,19 @@ Use `Write-Verbose` for informational messages. The user can decide whether to s
providing the **Verbose** parameter.

```powershell
function Get-MeaningOfLife
{
function Get-MeaningOfLife {
[CmdletBinding()]Param() # makes it possible to support Verbose output

Write-Verbose 'Computing the answer to the ultimate question of life, the universe and everything'
Write-Output 42
}

function Show-Something
{
function Show-Something {
Write-Host 'Show something on screen'
}
```

<!-- links reference -->

[01]: /powershell/module/microsoft.powershell.utility/write-host
[02]: /powershell/module/microsoft.powershell.utility/write-output
[03]: /powershell/module/microsoft.powershell.utility/write-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ Function Test-Function
```

<!-- links reference -->

[01]: /powershell/module/microsoft.powershell.utility/write-verbose
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ All other keys are optional and the order you place them doesn't matter. To lear
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_module_manifests
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Use equality operator (==) instead of an equal sign (=) as an assignment operator
description: Use the PowerShell equality operator (-eq) instead of assignment (=) in conditional statements
ms.date: 06/05/2026
ms.topic: reference
title: PossibleIncorrectUsageOfAssignmentOperator
Expand Down Expand Up @@ -33,8 +33,7 @@ expression in extra parentheses. An exception applies when `$null` is used on th
because there's no use case for it. For example:

```powershell
if (($shortVariableName = $SuperLongVariableName['SpecialItem']['AnotherItem']))
{
if (($shortVariableName = $SuperLongVariableName['SpecialItem']['AnotherItem'])) {
...
}
```
Expand Down Expand Up @@ -74,6 +73,5 @@ if ($a = Get-Something) # Only execute action if command returns something and a
```

<!-- link references -->

[01]: /powershell/module/microsoft.powershell.core/about/about_assignment_operators
[02]: /powershell/module/microsoft.powershell.core/about/about_comparison_operators#-eq-and--ne
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ The possible values are:
- `end`: The comment is placed at the end of the function definition body

<!-- link references -->

[01]: /powershell/scripting/developer/help/writing-comment-based-help-topics
[02]: /powershell/scripting/developer/help/writing-help-for-windows-powershell-cmdlets
[03]: /powershell/utility-modules/platyps/create-help-using-platyps
Loading
Loading