diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AlignAssignmentStatement.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AlignAssignmentStatement.md index 18a2541..c12847e 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AlignAssignmentStatement.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AlignAssignmentStatement.md @@ -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 @@ -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 +} +``` \ No newline at end of file diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md index a483bf2..a7dc262 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidAssignmentToAutomaticVariable.md @@ -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]. + + +## How + +Use variable names in functions or their parameters that do not conflict with automatic variables. + ## Example ### Noncompliant diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md index e50d150..c34701d 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidDefaultValueSwitchParameter.md @@ -59,6 +59,7 @@ function Test-Script [switch] $Switch ) + ... } ``` diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md index dcd2cf9..a6385dc 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidExclaimOperator.md @@ -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 = @{ @@ -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`. diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md index 2778e08..b72fc62 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalAliases.md @@ -1,5 +1,5 @@ --- -description: Avoid global aliases +description: Avoid global aliases. ms.date: 05/28/2026 ms.topic: reference title: AvoidGlobalAliases @@ -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]. diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md index c3c03d3..80dd839 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalFunctions.md @@ -33,5 +33,4 @@ function functionName {} ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_scopes diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md index ba8413e..df473c2 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidGlobalVars.md @@ -1,5 +1,5 @@ --- -description: Avoid global variables +description: Avoid global variables. ms.date: 06/23/2026 ms.topic: reference title: AvoidGlobalVars @@ -57,7 +57,6 @@ $var1 ``` - [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 diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md index 4a73730..35631e9 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidInvokingEmptyMembers.md @@ -1,5 +1,5 @@ --- -description: Avoid invoking empty members +description: Avoid invoking empty members. ms.date: 05/28/2026 ms.topic: reference title: AvoidInvokingEmptyMembers @@ -34,5 +34,4 @@ $MyString.('length') ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_operators#member-access-operator- diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidNullOrEmptyHelpMessageAttribute.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidNullOrEmptyHelpMessageAttribute.md index 5535f4b..0706e29 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidNullOrEmptyHelpMessageAttribute.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidNullOrEmptyHelpMessageAttribute.md @@ -72,5 +72,4 @@ Function GoodFuncHelpMessage ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters#helpmessage-argument diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md index 0c7ac00..7fd2117 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidReservedWordsAsFunctionNames.md @@ -37,5 +37,4 @@ function myFunction { ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_reserved_words diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidShouldContinueWithoutForce.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidShouldContinueWithoutForce.md index 8a9ce7c..f6fc10d 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidShouldContinueWithoutForce.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidShouldContinueWithoutForce.md @@ -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 @@ -60,6 +60,5 @@ Function Test-ShouldContinue ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute [02]: /powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidTrailingWhitespace.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidTrailingWhitespace.md index 58e7bc8..02c02d2 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidTrailingWhitespace.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidTrailingWhitespace.md @@ -52,5 +52,4 @@ Get-Process ` ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_parsing diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingAllowUnencryptedAuthentication.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingAllowUnencryptedAuthentication.md index 7b04177..2e76b19 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingAllowUnencryptedAuthentication.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingAllowUnencryptedAuthentication.md @@ -34,6 +34,5 @@ Invoke-WebRequest foo ``` - [01]: /powershell/module/microsoft.powershell.utility/invoke-webrequest [02]: /powershell/module/microsoft.powershell.utility/invoke-restmethod diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingConvertToSecureStringWithPlainText.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingConvertToSecureStringWithPlainText.md index 7375671..30a35f2 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingConvertToSecureStringWithPlainText.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingConvertToSecureStringWithPlainText.md @@ -39,6 +39,5 @@ $SecureUserInput = Read-Host 'Please enter your secure code' -AsSecureString ``` - [01]: /dotnet/api/system.security.securestring [02]: https://www.powershellgallery.com/packages/Microsoft.PowerShell.SecretStore diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPlainTextForPassword.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPlainTextForPassword.md index 0e7280e..0334ec7 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPlainTextForPassword.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPlainTextForPassword.md @@ -60,5 +60,4 @@ function Test-Script ``` - [01]: /dotnet/api/system.security.securestring diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPositionalParameters.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPositionalParameters.md index 2f6ecb9..4bd6a78 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPositionalParameters.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingPositionalParameters.md @@ -41,7 +41,7 @@ Get-Command -Noun ChildItem -Module Microsoft.PowerShell.Management Rules = @{ PSAvoidUsingPositionalParameters = @{ CommandAllowList = 'Join-Path', 'MyCmdletOrScript' - Enable = $true + Enable = $true } } ``` diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingWriteHost.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingWriteHost.md index e6e1539..2160623 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingWriteHost.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidUsingWriteHost.md @@ -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' } ``` - [01]: /powershell/module/microsoft.powershell.utility/write-host [02]: /powershell/module/microsoft.powershell.utility/write-output [03]: /powershell/module/microsoft.powershell.utility/write-verbose diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/DSCUseVerboseMessageInDSCResource.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/DSCUseVerboseMessageInDSCResource.md index 3fa9754..3154111 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/DSCUseVerboseMessageInDSCResource.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/DSCUseVerboseMessageInDSCResource.md @@ -41,5 +41,4 @@ Function Test-Function ``` - [01]: /powershell/module/microsoft.powershell.utility/write-verbose diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/MissingModuleManifestField.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/MissingModuleManifestField.md index 436c783..0b50edf 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/MissingModuleManifestField.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/MissingModuleManifestField.md @@ -49,5 +49,4 @@ All other keys are optional and the order you place them doesn't matter. To lear ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_module_manifests diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/PossibleIncorrectUsageOfAssignmentOperator.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/PossibleIncorrectUsageOfAssignmentOperator.md index 8408ac0..eb8761f 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/PossibleIncorrectUsageOfAssignmentOperator.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/PossibleIncorrectUsageOfAssignmentOperator.md @@ -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 @@ -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'])) { ... } ``` @@ -74,6 +73,5 @@ if ($a = Get-Something) # Only execute action if command returns something and a ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_assignment_operators [02]: /powershell/module/microsoft.powershell.core/about/about_comparison_operators#-eq-and--ne \ No newline at end of file diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/ProvideCommentHelp.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/ProvideCommentHelp.md index f53c0e9..2f7567b 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/ProvideCommentHelp.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/ProvideCommentHelp.md @@ -126,7 +126,6 @@ The possible values are: - `end`: The comment is placed at the end of the function definition body - [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 diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md index fca031e..2d96944 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/README.md @@ -1,92 +1,179 @@ --- description: List of PSScriptAnalyzer rules -ms.date: 03/20/2026 +ms.date: 06/25/2026 ms.topic: reference title: List of PSScriptAnalyzer rules --- # PSScriptAnalyzer Rules -The PSScriptAnalyzer contains the following rule definitions. +The PSScriptAnalyzer module includes the following built-in rule definitions. You can disable most +configurable rules by setting the `Enable` property to `$false` in a custom rule configuration file. +Rules listed as _Always enabled_ can't be disabled using configuration. However, there are two ways +to avoid rules you don't want to use: -| Rule | Severity | Enabled by default | Configurable | -| ------------------------------------------------------------------------------------------------- | ----------- | :----------------: | :-------------: | -| [AlignAssignmentStatement](./AlignAssignmentStatement.md) | Warning | No | Yes | -| [AvoidAssignmentToAutomaticVariable](./AvoidAssignmentToAutomaticVariable.md) | Warning | Yes | | -| [AvoidDefaultValueForMandatoryParameter](./AvoidDefaultValueForMandatoryParameter.md) | Warning | Yes | | -| [AvoidDefaultValueSwitchParameter](./AvoidDefaultValueSwitchParameter.md) | Warning | Yes | | -| [AvoidExclaimOperator](./AvoidExclaimOperator.md) | Warning | No | | -| [AvoidGlobalAliases1](./AvoidGlobalAliases.md) | Warning | Yes | | -| [AvoidGlobalFunctions](./AvoidGlobalFunctions.md) | Warning | Yes | | -| [AvoidGlobalVars](./AvoidGlobalVars.md) | Warning | Yes | | -| [AvoidInvokingEmptyMembers](./AvoidInvokingEmptyMembers.md) | Warning | Yes | | -| [AvoidLongLines](./AvoidLongLines.md) | Warning | No | Yes | -| [AvoidMultipleTypeAttributes1](./AvoidMultipleTypeAttributes.md) | Warning | Yes | | -| [AvoidNullOrEmptyHelpMessageAttribute](./AvoidNullOrEmptyHelpMessageAttribute.md) | Warning | Yes | | -| [AvoidOverwritingBuiltInCmdlets](./AvoidOverwritingBuiltInCmdlets.md) | Warning | Yes | Yes | -| [AvoidReservedWordsAsFunctionNames](./AvoidReservedWordsAsFunctionNames.md) | Warning | Yes | | -| [AvoidSemicolonsAsLineTerminators](./AvoidSemicolonsAsLineTerminators.md) | Warning | No | | -| [AvoidShouldContinueWithoutForce](./AvoidShouldContinueWithoutForce.md) | Warning | Yes | | -| [AvoidTrailingWhitespace](./AvoidTrailingWhitespace.md) | Warning | Yes | | -| [AvoidUsingAllowUnencryptedAuthentication](./AvoidUsingAllowUnencryptedAuthentication.md) | Warning | Yes | | -| [AvoidUsingBrokenHashAlgorithms](./AvoidUsingBrokenHashAlgorithms.md) | Warning | Yes | | -| [AvoidUsingCmdletAliases](./AvoidUsingCmdletAliases.md) | Warning | Yes | Yes2 | -| [AvoidUsingComputerNameHardcoded](./AvoidUsingComputerNameHardcoded.md) | Error | Yes | | -| [AvoidUsingConvertToSecureStringWithPlainText](./AvoidUsingConvertToSecureStringWithPlainText.md) | Error | Yes | | -| [AvoidUsingDeprecatedManifestFields](./AvoidUsingDeprecatedManifestFields.md) | Warning | Yes | | -| [AvoidUsingDoubleQuotesForConstantString](./AvoidUsingDoubleQuotesForConstantString.md) | Information | No | | -| [AvoidUsingEmptyCatchBlock](./AvoidUsingEmptyCatchBlock.md) | Warning | Yes | | -| [AvoidUsingInvokeExpression](./AvoidUsingInvokeExpression.md) | Warning | Yes | | -| [AvoidUsingPlainTextForPassword](./AvoidUsingPlainTextForPassword.md) | Warning | Yes | | -| [AvoidUsingPositionalParameters](./AvoidUsingPositionalParameters.md) | Warning | Yes | | -| [AvoidUsingUsernameAndPasswordParams](./AvoidUsingUsernameAndPasswordParams.md) | Error | Yes | | -| [AvoidUsingWMICmdlet](./AvoidUsingWMICmdlet.md) | Warning | Yes | | -| [AvoidUsingWriteHost](./AvoidUsingWriteHost.md) | Warning | Yes | | -| [DSCDscExamplesPresent](./DSCDscExamplesPresent.md) | Information | Yes | | -| [DSCDscTestsPresent](./DSCDscTestsPresent.md) | Information | Yes | | -| [DSCReturnCorrectTypesForDSCFunctions](./DSCReturnCorrectTypesForDSCFunctions.md) | Information | Yes | | -| [DSCStandardDSCFunctionsInResource](./DSCStandardDSCFunctionsInResource.md) | Error | Yes | | -| [DSCUseIdenticalMandatoryParametersForDSC](./DSCUseIdenticalMandatoryParametersForDSC.md) | Error | Yes | | -| [DSCUseIdenticalParametersForDSC](./DSCUseIdenticalParametersForDSC.md) | Error | Yes | | -| [DSCUseVerboseMessageInDSCResource](./DSCUseVerboseMessageInDSCResource.md) | Error | Yes | | -| [MisleadingBacktick](./MisleadingBacktick.md) | Warning | Yes | | -| [MissingModuleManifestField](./MissingModuleManifestField.md) | Warning | Yes | | -| [PlaceCloseBrace](./PlaceCloseBrace.md) | Warning | No | Yes | -| [PlaceOpenBrace](./PlaceOpenBrace.md) | Warning | No | Yes | -| [PossibleIncorrectComparisonWithNull](./PossibleIncorrectComparisonWithNull.md) | Warning | Yes | | -| [PossibleIncorrectUsageOfAssignmentOperator](./PossibleIncorrectUsageOfAssignmentOperator.md) | Warning | Yes | | -| [PossibleIncorrectUsageOfRedirectionOperator](./PossibleIncorrectUsageOfRedirectionOperator.md) | Warning | Yes | | -| [ProvideCommentHelp](./ProvideCommentHelp.md) | Information | Yes | Yes | -| [ReservedCmdletChar](./ReservedCmdletChar.md) | Error | Yes | | -| [ReservedParams](./ReservedParams.md) | Error | Yes | | -| [ReviewUnusedParameter](./ReviewUnusedParameter.md) | Warning | Yes | Yes2 | -| [ShouldProcess](./ShouldProcess.md) | Warning | Yes | | -| [UseApprovedVerbs](./UseApprovedVerbs.md) | Warning | Yes | | -| [UseBOMForUnicodeEncodedFile](./UseBOMForUnicodeEncodedFile.md) | Warning | Yes | | -| [UseCmdletCorrectly](./UseCmdletCorrectly.md) | Warning | Yes | | -| [UseCompatibleCmdlets](./UseCompatibleCmdlets.md) | Warning | Yes | Yes2 | -| [UseCompatibleCommands](./UseCompatibleCommands.md) | Warning | No | Yes | -| [UseCompatibleSyntax](./UseCompatibleSyntax.md) | Warning | No | Yes | -| [UseCompatibleTypes](./UseCompatibleTypes.md) | Warning | No | Yes | -| [UseConsistentIndentation](./UseConsistentIndentation.md) | Warning | No | Yes | -| [UseConsistentParameterSetName](./UseConsistentParameterSetName.md) | Warning | No | | -| [UseConsistentParametersKind](./UseConsistentParametersKind.md) | Warning | No | Yes | -| [UseConsistentWhitespace](./UseConsistentWhitespace.md) | Warning | No | Yes | -| [UseConstrainedLanguageMode](./UseConstrainedLanguageMode.md) | Warning | No | Yes | -| [UseCorrectCasing](./UseCorrectCasing.md) | Information | No | Yes | -| [UseDeclaredVarsMoreThanAssignments](./UseDeclaredVarsMoreThanAssignments.md) | Warning | Yes | | -| [UseLiteralInitializerForHashtable](./UseLiteralInitializerForHashtable.md) | Warning | Yes | | -| [UseOutputTypeCorrectly](./UseOutputTypeCorrectly.md) | Information | Yes | | -| [UseProcessBlockForPipelineCommand](./UseProcessBlockForPipelineCommand.md) | Warning | Yes | | -| [UsePSCredentialType](./UsePSCredentialType.md) | Warning | Yes | | -| [UseShouldProcessForStateChangingFunctions](./UseShouldProcessForStateChangingFunctions.md) | Warning | Yes | | -| [UseSingleValueFromPipelineParameter](./UseSingleValueFromPipelineParameter.md) | Warning | No | | -| [UseSingularNouns](./UseSingularNouns.md) | Warning | Yes | Yes | -| [UseSupportsShouldProcess](./UseSupportsShouldProcess.md) | Warning | Yes | | -| [UseToExportFieldsInManifest](./UseToExportFieldsInManifest.md) | Warning | Yes | | -| [UseUsingScopeModifierInNewRunspaces](./UseUsingScopeModifierInNewRunspaces.md) | Warning | Yes | | -| [UseUTF8EncodingForHelpFile](./UseUTF8EncodingForHelpFile.md) | Warning | Yes | | + The PSScriptAnalyzer module includes the following built-in rule definitions. For rules that + support settings, you can enable or disable them by setting the `Enable` configuration property in + a custom settings file. Rules listed as _Always enabled_ don't expose a per-rule `Enable` property. + There are two way to avoid using these rules: -- 1 Rule is not available on all PowerShell versions, editions, or OS platforms. See the - rule's documentation for details. -- 2 The rule has a configurable property, but the rule can't be disabled like other - configurable rules. +- Create a custom rule configuration file to include only the rules you want or exclude the rules + you don't want. +- Add the appropriate rule suppression attributes to your code to suppress the rule for specific + code blocks. For more information, see the _Suppressing rules_ section of + [Using PSScriptAnalyzer][01]. + +| Rule | Severity | Default state | Configurable | +| -------------------------------------------------- | ----------- | :------------: | :----------: | +| [AlignAssignmentStatement][02] | Warning | Disabled | Yes | +| [AvoidAssignmentToAutomaticVariable][03] | Warning | Always enabled | | +| [AvoidDefaultValueForMandatoryParameter][04] | Warning | Always enabled | | +| [AvoidDefaultValueSwitchParameter][05] | Warning | Always enabled | | +| [AvoidExclaimOperator][06] | Warning | Disabled | Yes | +| [AvoidGlobalAliases][07] | Warning | Always enabled | | +| [AvoidGlobalFunctions][08] | Warning | Always enabled | | +| [AvoidGlobalVars][09] | Warning | Always enabled | | +| [AvoidInvokingEmptyMembers][10] | Warning | Always enabled | | +| [AvoidLongLines][11] | Warning | Disabled | Yes | +| [AvoidMultipleTypeAttributes][12] | Warning | Always enabled | | +| [AvoidNullOrEmptyHelpMessageAttribute][13] | Warning | Always enabled | | +| [AvoidOverwritingBuiltInCmdlets][14] | Warning | Enabled | Yes | +| [AvoidReservedWordsAsFunctionNames][15] | Warning | Always enabled | | +| [AvoidSemicolonsAsLineTerminators][16] | Warning | Disabled | Yes | +| [AvoidShouldContinueWithoutForce][17] | Warning | Always enabled | | +| [AvoidTrailingWhitespace][18] | Warning | Always enabled | | +| [AvoidUsingAllowUnencryptedAuthentication][19] | Warning | Always enabled | | +| [AvoidUsingBrokenHashAlgorithms][20] | Warning | Always enabled | | +| [AvoidUsingCmdletAliases][21] | Warning | Always enabled | Yes | +| [AvoidUsingComputerNameHardcoded][22] | Error | Always enabled | | +| [AvoidUsingConvertToSecureStringWithPlainText][23] | Error | Always enabled | | +| [AvoidUsingDeprecatedManifestFields][24] | Warning | Always enabled | | +| [AvoidUsingDoubleQuotesForConstantString][25] | Information | Disabled | Yes | +| [AvoidUsingEmptyCatchBlock][26] | Warning | Always enabled | | +| [AvoidUsingInvokeExpression][27] | Warning | Always enabled | | +| [AvoidUsingPlainTextForPassword][28] | Warning | Always enabled | | +| [AvoidUsingPositionalParameters][29] | Warning | Always enabled | | +| [AvoidUsingUsernameAndPasswordParams][30] | Error | Always enabled | | +| [AvoidUsingWMICmdlet][31] | Warning | Always enabled | | +| [AvoidUsingWriteHost][32] | Warning | Always enabled | | +| [DSCDscExamplesPresent][33] | Information | Always enabled | | +| [DSCDscTestsPresent][34] | Information | Always enabled | | +| [DSCReturnCorrectTypesForDSCFunctions][35] | Information | Always enabled | | +| [DSCStandardDSCFunctionsInResource][36] | Error | Always enabled | | +| [DSCUseIdenticalMandatoryParametersForDSC][37] | Error | Always enabled | | +| [DSCUseIdenticalParametersForDSC][38] | Error | Always enabled | | +| [DSCUseVerboseMessageInDSCResource][39] | Error | Always enabled | | +| [MisleadingBacktick][40] | Warning | Always enabled | | +| [MissingModuleManifestField][41] | Warning | Always enabled | | +| [PlaceCloseBrace][42] | Warning | Disabled | Yes | +| [PlaceOpenBrace][43] | Warning | Disabled | Yes | +| [PossibleIncorrectComparisonWithNull][44] | Warning | Always enabled | | +| [PossibleIncorrectUsageOfAssignmentOperator][45] | Warning | Always enabled | | +| [PossibleIncorrectUsageOfRedirectionOperator][46] | Warning | Always enabled | | +| [ProvideCommentHelp][47] | Information | Enabled | Yes | +| [ReservedCmdletChar][48] | Error | Always enabled | | +| [ReservedParams][49] | Error | Always enabled | | +| [ReviewUnusedParameter][50] | Warning | Always enabled | Yes | +| [ShouldProcess][51] | Warning | Always enabled | | +| [UseApprovedVerbs][52] | Warning | Always enabled | | +| [UseBOMForUnicodeEncodedFile][53] | Warning | Always enabled | | +| [UseCmdletCorrectly][54] | Warning | Always enabled | | +| [UseCompatibleCmdlets][55] | Warning | Always enabled | Yes | +| [UseCompatibleCommands][56] | Warning | Disabled | Yes | +| [UseCompatibleSyntax][57] | Warning | Disabled | Yes | +| [UseCompatibleTypes][58] | Warning | Disabled | Yes | +| [UseConsistentIndentation][59] | Warning | Disabled | Yes | +| [UseConsistentParameterSetName][60] | Warning | Disabled | Yes | +| [UseConsistentParametersKind][61] | Warning | Disabled | Yes | +| [UseConsistentWhitespace][62] | Warning | Disabled | Yes | +| [UseConstrainedLanguageMode][63] | Warning | Disabled | Yes | +| [UseCorrectCasing][64] | Information | Disabled | Yes | +| [UseDeclaredVarsMoreThanAssignments][65] | Warning | Always enabled | | +| [UseLiteralInitializerForHashtable][66] | Warning | Always enabled | | +| [UseOutputTypeCorrectly][67] | Information | Always enabled | | +| [UseProcessBlockForPipelineCommand][68] | Warning | Always enabled | | +| [UsePSCredentialType][69] | Warning | Always enabled | | +| [UseShouldProcessForStateChangingFunctions][70] | Warning | Always enabled | | +| [UseSingleValueFromPipelineParameter][71] | Warning | Disabled | Yes | +| [UseSingularNouns][72] | Warning | Enabled | Yes | +| [UseSupportsShouldProcess][73] | Warning | Always enabled | | +| [UseToExportFieldsInManifest][74] | Warning | Always enabled | | +| [UseUsingScopeModifierInNewRunspaces][75] | Warning | Always enabled | | +| [UseUTF8EncodingForHelpFile][76] | Warning | Always enabled | | + + +[01]: ../using-scriptanalyzer.md#suppressing-rules +[02]: AlignAssignmentStatement.md +[03]: AvoidAssignmentToAutomaticVariable.md +[04]: AvoidDefaultValueForMandatoryParameter.md +[05]: AvoidDefaultValueSwitchParameter.md +[06]: AvoidExclaimOperator.md +[07]: AvoidGlobalAliases.md +[08]: AvoidGlobalFunctions.md +[09]: AvoidGlobalVars.md +[10]: AvoidInvokingEmptyMembers.md +[11]: AvoidLongLines.md +[12]: AvoidMultipleTypeAttributes.md +[13]: AvoidNullOrEmptyHelpMessageAttribute.md +[14]: AvoidOverwritingBuiltInCmdlets.md +[15]: AvoidReservedWordsAsFunctionNames.md +[16]: AvoidSemicolonsAsLineTerminators.md +[17]: AvoidShouldContinueWithoutForce.md +[18]: AvoidTrailingWhitespace.md +[19]: AvoidUsingAllowUnencryptedAuthentication.md +[20]: AvoidUsingBrokenHashAlgorithms.md +[21]: AvoidUsingCmdletAliases.md +[22]: AvoidUsingComputerNameHardcoded.md +[23]: AvoidUsingConvertToSecureStringWithPlainText.md +[24]: AvoidUsingDeprecatedManifestFields.md +[25]: AvoidUsingDoubleQuotesForConstantString.md +[26]: AvoidUsingEmptyCatchBlock.md +[27]: AvoidUsingInvokeExpression.md +[28]: AvoidUsingPlainTextForPassword.md +[29]: AvoidUsingPositionalParameters.md +[30]: AvoidUsingUsernameAndPasswordParams.md +[31]: AvoidUsingWMICmdlet.md +[32]: AvoidUsingWriteHost.md +[33]: DSCDscExamplesPresent.md +[34]: DSCDscTestsPresent.md +[35]: DSCReturnCorrectTypesForDSCFunctions.md +[36]: DSCStandardDSCFunctionsInResource.md +[37]: DSCUseIdenticalMandatoryParametersForDSC.md +[38]: DSCUseIdenticalParametersForDSC.md +[39]: DSCUseVerboseMessageInDSCResource.md +[40]: MisleadingBacktick.md +[41]: MissingModuleManifestField.md +[42]: PlaceCloseBrace.md +[43]: PlaceOpenBrace.md +[44]: PossibleIncorrectComparisonWithNull.md +[45]: PossibleIncorrectUsageOfAssignmentOperator.md +[46]: PossibleIncorrectUsageOfRedirectionOperator.md +[47]: ProvideCommentHelp.md +[48]: ReservedCmdletChar.md +[49]: ReservedParams.md +[50]: ReviewUnusedParameter.md +[51]: ShouldProcess.md +[52]: UseApprovedVerbs.md +[53]: UseBOMForUnicodeEncodedFile.md +[54]: UseCmdletCorrectly.md +[55]: UseCompatibleCmdlets.md +[56]: UseCompatibleCommands.md +[57]: UseCompatibleSyntax.md +[58]: UseCompatibleTypes.md +[59]: UseConsistentIndentation.md +[60]: UseConsistentParameterSetName.md +[61]: UseConsistentParametersKind.md +[62]: UseConsistentWhitespace.md +[63]: UseConstrainedLanguageMode.md +[64]: UseCorrectCasing.md +[65]: UseDeclaredVarsMoreThanAssignments.md +[66]: UseLiteralInitializerForHashtable.md +[67]: UseOutputTypeCorrectly.md +[68]: UseProcessBlockForPipelineCommand.md +[69]: UsePSCredentialType.md +[70]: UseShouldProcessForStateChangingFunctions.md +[71]: UseSingleValueFromPipelineParameter.md +[72]: UseSingularNouns.md +[73]: UseSupportsShouldProcess.md +[74]: UseToExportFieldsInManifest.md +[75]: UseUsingScopeModifierInNewRunspaces.md +[76]: UseUTF8EncodingForHelpFile.md diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/ShouldProcess.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/ShouldProcess.md index cb79562..3778828 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/ShouldProcess.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/ShouldProcess.md @@ -22,7 +22,7 @@ Violations occur when: To fix this violation, ensure that `ShouldProcess` calls are paired with the `SupportsShouldProcess` attribute declaration. -To learn more, see the following articles: +For more information, see the following articles: - [about_Functions_Advanced_Methods][01] - [about_Functions_CmdletBindingAttribute][02] @@ -75,7 +75,6 @@ function Set-File ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods [02]: /powershell/module/microsoft.powershell.core/about/about_Functions_CmdletBindingAttribute [03]: /powershell/scripting/learn/deep-dives/everything-about-shouldprocess diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseApprovedVerbs.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseApprovedVerbs.md index 0223627..6991973 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseApprovedVerbs.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseApprovedVerbs.md @@ -39,5 +39,4 @@ function Update-Item { ``` - [01]: /powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCmdlets.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCmdlets.md index 7675bcd..cc339f0 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCmdlets.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCmdlets.md @@ -62,5 +62,4 @@ The `core-6.0.2-*` files were removed in PSScriptAnalyzer 1.18 because PowerShel end of life. - [01]: https://github.com/PowerShell/PSScriptAnalyzer/blob/main/Utils/New-CommandDataFile.ps1 diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCommands.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCommands.md index 229187d..e5c72b6 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCommands.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleCommands.md @@ -180,6 +180,5 @@ This parameter specifies commands to exclude from compatibility checks. It accep command-name strings. The default value is `@()`. - [01]: https://github.com/PowerShell/PSScriptAnalyzer/tree/main/PSCompatibilityCollector [02]: https://github.com/PowerShell/PSScriptAnalyzer/tree/main/PSCompatibilityCollector/optional_profiles diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleTypes.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleTypes.md index 8b9a633..dc98ecd 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleTypes.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseCompatibleTypes.md @@ -202,6 +202,5 @@ This parameter specifies the full names of types or type accelerators to exclude checks. It accepts an array of type-name strings. The default value is `@()`. - [01]: https://github.com/PowerShell/PSScriptAnalyzer/tree/main/PSCompatibilityCollector [02]: https://github.com/PowerShell/PSScriptAnalyzer/tree/main/PSCompatibilityCollector/optional_profiles diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseConstrainedLanguageMode.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseConstrainedLanguageMode.md index 7661e11..ca2a3b6 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseConstrainedLanguageMode.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseConstrainedLanguageMode.md @@ -279,7 +279,6 @@ Use `IgnoreSignatures = $true` when: - [PowerShell Constrained Language Mode and the Dot-Source Operator][02] - [01]: /powershell/module/microsoft.powershell.core/about/about_language_modes [02]: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode-and-the-dot-source-operator/ [03]: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/ diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseOutputTypeCorrectly.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseOutputTypeCorrectly.md index 9914163..9854cdf 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseOutputTypeCorrectly.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseOutputTypeCorrectly.md @@ -48,5 +48,4 @@ function Get-Foo ``` - [01]: /powershell/module/microsoft.powershell.core/about/about_functions_outputtypeattribute diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseSingleValueFromPipelineParameter.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseSingleValueFromPipelineParameter.md index b59fee9..8796054 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseSingleValueFromPipelineParameter.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseSingleValueFromPipelineParameter.md @@ -1,6 +1,6 @@ --- description: Use a single ValueFromPipeline parameter per parameter set -ms.date: 06/11/2026 +ms.date: 06/25/2026 ms.topic: reference title: UseSingleValueFromPipelineParameter --- @@ -59,8 +59,8 @@ function Process-Data { ## Suppression -To suppress this rule for a specific parameter set, use the `SuppressMessage` attribute with the -parameter set name: +This rule is disabled by default. If you have enabled it in your configuration but want to suppress +it for a specific function, you can use the `SuppressMessage` attribute: ```powershell function Process-Data { diff --git a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseUsingScopeModifierInNewRunspaces.md b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseUsingScopeModifierInNewRunspaces.md index 17177f7..9245c32 100644 --- a/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseUsingScopeModifierInNewRunspaces.md +++ b/reference/docs-conceptual/PSScriptAnalyzer/Rules/UseUsingScopeModifierInNewRunspaces.md @@ -19,7 +19,7 @@ initialize the variable within the scriptblock itself. This rule applies to: - `Invoke-Command`- Only with the **ComputerName** or **Session** parameter. - `Workflow { InlineScript {} }` (supported only in Windows PowerShell 5.1 and earlier; not - available in PowerShell 7+) + available in PowerShell 6 or higher) - `Foreach-Object` - Only with the **Parallel** parameter - `Start-Job` - `Start-ThreadJob`