This rule detects misaligned assignment operators in hashtables and enum definitions. Consecutive assignment statements are easier to read and maintain when their assignment operators align vertically. Default state: Disabled.
- Code
PSAlignAssignmentStatement- Severity
- warning
Avoid using automatic variable names in your functions and parameters. This rule detects assignments to automatic variables and parameter names that use automatic variable names. PowerShell automatically defines variables that store internal state information and manages them on its own. Even though you _can_ override many automatic variables, doing so can have unexpected effects for users and make your code harder to maintain and debug. Default state: Always enabled.
- Code
PSAvoidAssignmentToAutomaticVariable- Severity
- warning
This rule detects when mandatory parameters have default values assigned. Mandatory parameters shouldn't have default values because they can't be used. When a parameter is marked as mandatory, PowerShell always prompts the user for a value if one isn't supplied when calling the function. Any default value assigned to a mandatory parameter is unreachable and serves no purpose. Default state: Always enabled.
- Code
PSAvoidDefaultValueForMandatoryParameter- Severity
- warning
This rule detects switch parameters that are assigned a default value of $true. Switch parameters shouldn't have default values. By design, a switch parameter is $false when not specified and $true when included in the command. Assigning a default value of $true to a switch parameter violates this design principle and can cause unexpected behavior. Default state: Always enabled.
- Code
PSAvoidDefaultValueSwitchParameter- Severity
- warning
This rule checks for the use of New-Variable with a dynamic name. Don't create variables with dynamic names. A dynamic name is a name constructed using string concatenation or interpolation. Dynamic names make the code difficult to understand and can lead to unexpected behavior if the variable names aren't unique. Default state: Disabled.
- Code
PSAvoidDynamicallyCreatingVariableNames- Severity
- information
This rule detects the use of the negation operator (an exclamation mark, !) and recommends using the -not operator instead for improved readability and consistency with PowerShell conventions. Default state: Disabled.
- Code
PSAvoidExclaimOperator- Severity
- warning
This rule detects the use of the New-Alias command to create aliases in the global scope. Global aliases can unintentionally override existing aliases in the session, leading to unexpected behavior and name collisions. Name collisions make it difficult for module consumers to diagnose issues and maintain code reliability. Default state: Always enabled.
- Code
PSAvoidGlobalAliases- Severity
- warning
This rule detects function definitions that use the global: scope modifier on the function name to define a function in the global scope. Global functions can unintentionally override existing functions in the session, leading to unexpected behavior and name collisions. Name collisions make it difficult for module consumers to diagnose issues and maintain code reliability. Default state: Always enabled.
- Code
PSAvoidGlobalFunctions- Severity
- warning
You should avoid modifying global variables in your scripts and functions because other scripts or functions that run in the same session can depend on them. This can lead to unexpected behavior and make it difficult to debug your code. Default state: Always enabled.
- Code
PSAvoidGlobalVars- Severity
- warning
This rule detects expressions where the code uses the [member-access operator][01] (.) where the member name is dynamically constructed. Invoking dynamically constructed member names can introduce unexpected behavior and runtime errors. Ensure that member invocations use constant, literal member names rather than expressions that are evaluated at runtime. Default state: Always enabled.
- Code
PSAvoidInvokingEmptyMembers- Severity
- warning
This rule detects lines that exceed the configured maximum length, including leading spaces (indentation). The default maximum line length is 120 characters. Default state: Disabled.
- Code
PSAvoidLongLines- Severity
- warning
This rule detects parameters that have multiple type specifiers applied to them. Parameters shouldn't have multiple type specifiers. When you apply more than one type attribute to a parameter, it can lead to unexpected type coercion or runtime errors. Default state: Always enabled.
- Code
PSAvoidMultipleTypeAttributes- Severity
- warning
This rule detects [HelpMessage][01] attributes that contain null values, empty strings, or no value assignment. The HelpMessage attribute must contain a meaningful, non-empty string value. Omitting the value altogether causes a parse-time syntax error. Default state: Always enabled.
- Code
PSAvoidNullOrEmptyHelpMessageAttribute- Severity
- warning
This rule detects and warns when a script defines a function that uses the name of a built-in cmdlet available for a target PowerShell version and operating system. Overwriting built-in cmdlet names can cause confusing behavior because callers might run your function when they expected the platform cmdlet. Default state: Enabled.
- Code
PSAvoidOverwritingBuiltInCmdlets- Severity
- warning
This rule detects function names that use PowerShell reserved words. Using reserved words as function names causes errors or unexpected behavior in PowerShell scripts. Choose function names that don't conflict with any PowerShell reserved words. Default state: Always enabled.
- Code
PSAvoidReservedWordsAsFunctionNames- Severity
- warning
This rule detects semicolons used as line terminators at the end of statements. In PowerShell, line-ending semicolons are redundant and detract from code readability. Although semicolons serve as statement separators on a single line, using them as line terminators is discouraged. Avoid using semicolons at the end of lines. Default state: Disabled.
- Code
PSAvoidSemicolonsAsLineTerminators- Severity
- warning
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. Default state: Always enabled.
- Code
PSAvoidShouldContinueWithoutForce- Severity
- warning
This rule detects lines that end with trailing whitespace characters. Lines shouldn't end with trailing whitespace characters. Trailing whitespace makes diffs harder to review and can introduce subtle problems when line continuation uses a backtick (), because the backtick must be the last character on the line. Default state: Always enabled.
- Code
PSAvoidTrailingWhitespace- Severity
- information
This rule detects the **AllowUnencryptedAuthentication** parameter used with Invoke-WebRequest and Invoke-RestMethod cmdlets. When **AllowUnencryptedAuthentication** is used, it permits credentials and secrets to be transmitted over unencrypted connections, creating a security risk. Default state: Always enabled.
- Code
PSAvoidUsingAllowUnencryptedAuthentication- Severity
- warning
Avoid the **ArrayList** class for new development. The documentation for the [ArrayList class][01] recommends using the [System.Collections.Generic.List\<T\>][02] class instead. Default state: Disabled.
- Code
PSAvoidUsingArrayList- Severity
- warning
This rule detects the use of cryptographically broken hash algorithms MD5 and SHA-1. Avoid using hash algorithms MD5 and SHA-1. These algorithms are vulnerable to collision attacks and are no longer considered secure for cryptographic purposes. Default state: Always enabled.
- Code
PSAvoidUsingBrokenHashAlgorithms- Severity
- warning
This rule detects the use of cmdlet aliases and omission of the Get- prefix in implicit alias scenarios. An alias is an alternate name or nickname for a cmdlet or command element, such as a function, script, file, or executable file. While you can use aliases instead of the full command name, doing so reduces code readability and maintainability. Default state: Always enabled.
- Code
PSAvoidUsingCmdletAliases- Severity
- warning
This rule detects hard-coded computer names in the ComputerName parameter of cmdlets. Hard-coded computer names can expose sensitive information and reduce script portability. The ComputerName parameter should always be parameterized or dynamically assigned to ensure scripts are flexible and secure. Default state: Always enabled.
- Code
PSAvoidUsingComputerNameHardcoded- Severity
- error
This rule detects the use of the AsPlainText parameter with the ConvertTo-SecureString command, which bypasses encryption and exposes sensitive information in memory as plain text, defeating the purpose of [SecureString][01]. Default state: Always enabled.
- Code
PSAvoidUsingConvertToSecureStringWithPlainText- Severity
- error
This rule detects the usage of deprecated manifest fields in module manifest files (.psd1) that should be replaced with their modern equivalents. PowerShell 5.0 deprecated several fields in module manifest files (.psd1) in favor of new alternatives. Default state: Always enabled.
- Code
PSAvoidUsingDeprecatedManifestFields- Severity
- warning
This rule detects static strings enclosed with double quotes ("<text>") with text that doesn't contain variables, expressions, or special characters that require escaping. Default state: Disabled.
- Code
PSAvoidUsingDoubleQuotesForConstantString- Severity
- information
This rule detects empty catch blocks. Empty catch blocks are problematic because they silently suppress exceptions without any error handling, logging, or recovery action. This can mask bugs and make troubleshooting difficult. Always handle exceptions explicitly by using Write-Error to log the error, throw to propagate it, or provide appropriate recovery logic within the catch block. Default state: Always enabled.
- Code
PSAvoidUsingEmptyCatchBlock- Severity
- warning
This rule detects the use of the Invoke-Expression command, which poses security risks in your scripts and applications. You must be careful when using the Invoke-Expression command. It executes the specified string and returns the results. Default state: Always enabled.
- Code
PSAvoidUsingInvokeExpression- Severity
- warning
This rule detects function or script parameters with password-related names that are declared with a string type instead of the SecureString type. Password parameters that accept plaintext expose passwords and can compromise your system's security. You shouldn't accept passwords as plain text. Instead, use the [SecureString][01] type to store passwords securely. Default state: Always enabled.
- Code
PSAvoidUsingPlainTextForPassword- Severity
- warning
This rule detects when commands are called with three or more positional parameters instead of using named parameters. Using positional parameters reduces code readability and can introduce errors. It's possible that a future version of the cmdlet could change in a way that'll break existing scripts if they rely on parameter position. Default state: Enabled.
- Code
PSAvoidUsingPositionalParameters- Severity
- information
This rule detects functions that use separate username and password parameters instead of a single **PSCredential** object. Functions shouldn't use separate username or password parameters. To standardize command parameters, credentials should be accepted as objects of type **PSCredential**. Default state: Always enabled.
- Code
PSAvoidUsingUsernameAndPasswordParams- Severity
- error
This rule detects the use of Windows Management Instrumentation (WMI) cmdlets. Since PowerShell 3.0, you should use Common Information Model (CIM) cmdlets instead of WMI cmdlets. CIM cmdlets comply with WS-Management (WSMan) standards and the CIM standard, which enables management of Windows and non-Windows operating systems. Default state: Always enabled.
- Code
PSAvoidUsingWMICmdlet- Severity
- warning
This rule detects usage of Write-Host at script scope and in functions that don't use the Show verb. Write-Host is designed to produce display-only output in the host, like printing colored text or prompting users for input with Read-Host. It uses the ToString() method to write output, with results depending on the PowerShell host program. Default state: Always enabled.
- Code
PSAvoidUsingWriteHost- Severity
- warning
This rule detects if Desired State Configuration (DSC) examples for a given resource are present. Default state: Always enabled.
- Code
PSDSCDscExamplesPresent- Severity
- information
This rule detects if Desired State Configuration (DSC) tests for a given resource are present. Default state: Always enabled.
- Code
PSDSCDscTestsPresent- Severity
- information
This rule detects if functions in Desired State Configuration (DSC) resources have specific return objects. You'll need to ensure that each function returns the correct type. Default state: Always enabled.
- Code
PSDSCReturnCorrectTypesForDSCFunctions- Severity
- information
This rule detects if all Desired State Configuration (DSC) resources implement the correct functions. Add the missing functions to the resource. Default state: Always enabled.
- Code
PSDSCStandardDSCFunctionsInResource- Severity
- error
This rule detects if MOF-based Desired State Configuration (DSC) resources have properties declared with Key or Required attributes in a .mof file that aren't present as mandatory parameters in the corresponding functions. These properties must be declared as mandatory parameters in the Get-TargetResource, Set-TargetResource, and Test-TargetResource functions. Default state: Always enabled.
- Code
PSDSCUseIdenticalMandatoryParametersForDSC- Severity
- error
This rule detects if the Get-TargetResource, Set-TargetResource, and Test-TargetResource functions in a Desired State Configuration (DSC) resource all have identical parameters. If they don't match, you'll need to update the function parameters to be consistent across all three functions. Default state: Always enabled.
- Code
PSDSCUseIdenticalParametersForDSC- Severity
- error
This rule detects DSC resources that don't include Write-Verbose messages in their functions or scripts. It's a best practice to provide additional user information within commands, functions, and scripts using [Write-Verbose][01]. This helps users understand what's happening during execution. You should include Write-Verbose messages to make your code more informative and easier to debug. Default state: Always enabled.
- Code
PSDSCUseVerboseMessageInDSCResource- Severity
- information
PowerShell doesn't support unquoted literal values with multiple dots (.). Any value with two or more dots results in $null, which can lead to unexpected behavior or errors in the code. This rule identifies instances where such values are used. Default state: Disabled.
- Code
PSInvalidMultiDotValue- Severity
- warning
This rule detects lines where a trailing backtick is followed by one or more whitespace characters. A trailing backtick is used for line continuation only when it's the last character on the line. If whitespace follows the backtick on the same line the continuation doesn't work as intended, which can make the code look valid but behave unexpectedly. Default state: Always enabled.
- Code
PSMisleadingBacktick- Severity
- warning
This rule detects when a module manifest is missing a required field. A module manifest is a .psd1 file that contains a hash table. The keys and values in the hash table describe the contents and attributes of the module, define the prerequisites, and determine how the components are processed. Default state: Always enabled.
- Code
PSMissingModuleManifestField- Severity
- warning
This rule identifies instances where catch or finally blocks are present without an associated try block. Without a try block, the catch and finally are interpreted as commands and result in a runtime error, such as: Default state: Disabled.
- Code
PSMissingTryBlock- Severity
- warning
This rule detects closing braces (}) that aren't placed on a new line by themselves. When NoEmptyLineBefore is enabled, it also detects empty lines immediately before closing braces. Default state: Disabled.
- Code
PSPlaceCloseBrace- Severity
- warning
This rule detects opening braces ({) that don't follow a consistent style. Opening braces can be required on the same line as the preceding keyword or on the next line, based on configuration. You can also require a new line after the opening brace. Default state: Disabled.
- Code
PSPlaceOpenBrace- Severity
- warning
This rule detects comparisons where $null isn't on the left side of the comparison operator. To ensure that PowerShell performs comparisons correctly, the $null element should be on the left side of the operator. Default state: Always enabled.
- Code
PSPossibleIncorrectComparisonWithNull- Severity
- warning
This rule detects when conditional statements use = or == instead of the PowerShell equality operator (-eq). The rule looks for usages of == and = operators inside if, elseif, while, and do-while statements. In PowerShell, = represents the [assignment operator][01] and -eq represents the [equality comparison operator][02]. Default state: Always enabled.
- Code
PSPossibleIncorrectUsageOfAssignmentOperator- Severity
- information
This rule detects the use of the sequences > and >= in conditional statements where comparison operators are intended. This rule catches instances where > or >= appears inside if, elseif, while, and do-while statements, which are almost always unintentional. Default state: Always enabled.
- Code
PSPossibleIncorrectUsageOfRedirectionOperator- Severity
- warning
This rule detects when reserved characters are used in function or cmdlet names. You can't use reserved characters in a function or cmdlet name as they cause parsing or runtime errors. Remove reserved characters from your names. Default state: Always enabled.
- Code
PSReservedCmdletChar- Severity
- warning
This rule detects when you attempt to redefine [common parameters][01] in an advanced function. When you use the CmdletBinding or Parameter attributes, you're creating an advanced function. Common parameters are automatically available in advanced functions, so you can't redefine them. If you're trying to use a parameter name that conflicts with a common parameter, you need to change the name of your parameter to something else. Default state: Always enabled.
- Code
PSReservedParams- Severity
- error
This rule detects parameters that are declared but not used in a script, scriptblock, or function scope. You should consider removing unused parameters to improve code clarity and reduce confusion about your function's dependencies. Default state: Always enabled.
- Code
PSReviewUnusedParameter- Severity
- warning
This rule detects mismatches between SupportsShouldProcess declarations and ShouldProcess calls. When a cmdlet declares the SupportsShouldProcess attribute, it should also call the ShouldProcess method. Default state: Always enabled.
- Code
PSShouldProcess- Severity
- warning
This rule detects cmdlets that use unapproved verbs in their names. All cmdlets must use approved verbs. You can find approved verbs by running the Get-Verb command. If your cmdlet uses an unapproved verb, change it to an approved alternative. Default state: Always enabled.
- Code
PSUseApprovedVerbs- Severity
- warning
This rule detects files that are encoded with Unicode or other non-ASCII formats but don't include a Byte Order Mark (BOM). Default state: Always enabled.
- Code
PSUseBOMForUnicodeEncodedFile- Severity
- warning
This rule detects commands that are invoked without their required mandatory parameters. When you call a command, it must be invoked with the correct syntax and all mandatory parameters specified. Missing required parameters can cause commands to fail or behave unexpectedly. Default state: Always enabled.
- Code
PSUseCmdletCorrectly- Severity
- warning
This rule detects cmdlets that aren't available for the PowerShell edition, version, and operating system you target. The rule compares each cmdlet in your script against a compatibility allow list that ships with PSScriptAnalyzer. These files are in the following location: /path/to/PSScriptAnalyzerModule/Settings. Default state: Always enabled.
- Code
PSUseCompatibleCmdlets- Severity
- warning
This rule detects commands that aren't available on your targeted PowerShell platform. Default state: Disabled.
- Code
PSUseCompatibleCommands- Severity
- warning
This rule detects syntax elements that aren't compatible with your specified PowerShell target versions. When you run this rule from PowerShell 3 or 4, it can't detect syntax that's incompatible with those versions because those versions can't parse newer syntax constructs. Default state: Disabled.
- Code
PSUseCompatibleSyntax- Severity
- error
This rule detects types that aren't available by default on your targeted PowerShell platforms. Default state: Disabled.
- Code
PSUseCompatibleTypes- Severity
- warning
This rule detects inconsistent indentation patterns within a source file. Indentation should be consistent throughout your script. Default state: Disabled.
- Code
PSUseConsistentIndentation- Severity
- warning
This rule detects inconsistent parameter set naming and configuration issues that can cause runtime errors. Parameter set names in PowerShell are case-sensitive, unlike most other PowerShell elements. With this rule enabled, it's easier to debug your functions. This rule is **disabled** by default. Default state: Disabled.
- Code
PSUseConsistentParameterSetName- Severity
- warning
This rule detects when functions don't consistently use the same pattern for defining parameters. All functions should use the same parameter definition pattern to enforce consistent code style across the codebase. Rewrite any function that doesn't match the configured parameter definition kind. In simple scenarios, both the Inline and ParamBlock function definition patterns are functionally equivalent. Default state: Disabled.
- Code
PSUseConsistentParametersKind- Severity
- warning
This rule detects inconsistent or redundant whitespace around braces, parentheses, operators, separators, pipes, and parameter values. Use this rule to keep PowerShell code readable and consistently formatted. This rule is **disabled** by default. Default state: Disabled.
- Code
PSUseConsistentWhitespace- Severity
- warning
This rule detects PowerShell patterns that are restricted or not permitted in Constrained Language Mode (CLM). Use it when scripts must remain compatible with restricted PowerShell environments such as App Control for Business, AppLocker, or Just Enough Administration (JEA) endpoints. This rule is **disabled** by default. Default state: Disabled.
- Code
PSUseConstrainedLanguageMode- Severity
- warning
This rule detects inconsistent casing in cmdlet names, parameters, type names, keywords, and operators. PowerShell is case-insensitive wherever possible, so the casing of cmdlet names, parameters, keywords, and operators don't affect functionality. Default state: Disabled.
- Code
PSUseCorrectCasing- Severity
- information
This rule detects variables that are assigned a value but never used. A variable counts as "used" only when code references it in the same script block as its assignment. Variables that exist only as assignments add noise to the code and should be removed. Default state: Always enabled.
- Code
PSUseDeclaredVarsMoreThanAssignments- Severity
- warning
This rule detects hashtables created using the [hashtable]::new() method or the New-Object -TypeName hashtable cmdlet without passing an IEqualityComparer object. When you create a hashtable using [hashtable]::new() or New-Object -TypeName hashtable, the keys are looked up in a case-sensitive manner by default. Default state: Always enabled.
- Code
PSUseLiteralInitializerForHashtable- Severity
- warning
This rule detects when a function or script returns a different type than what is declared in the OutputType attribute. A function should return values that match the types specified in its OutputType attribute. Default state: Always enabled.
- Code
PSUseOutputTypeCorrectly- Severity
- information
This rule detects functions with pipeline-enabled parameters that handle input directly in the function body instead of using a process block. Functions that accept pipeline input through parameters should always process that input in a process block. Handling parameter input directly in the function body can lead to unexpected behavior because the function body executes once, while the process block executes for each object in the pipeline. Default state: Always enabled.
- Code
PSUseProcessBlockForPipelineCommand- Severity
- warning
This rule detects when a cmdlet or function defines a **Credential** parameter with a type other than **PSCredential**. Credential parameters should always use the **PSCredential** type to ensure proper handling of secure credential objects. Change any **Credential** parameter's type to **PSCredential** for consistency and security. Default state: Always enabled.
- Code
PSUsePSCredentialType- Severity
- warning
This rule detects functions with state-changing verbs that don't support ShouldProcess. Functions whose verbs change system state should support ShouldProcess to provide users with the ability to confirm or preview changes before execution. To enable this feature, set the SupportsShouldProcess argument to $true in the CmdletBinding attribute. Default state: Always enabled.
- Code
PSUseShouldProcessForStateChangingFunctions- Severity
- warning
This rule detects functions where multiple parameters within the same parameter set are marked as accepting pipeline input by value. Parameter sets should have at most one parameter with ValueFromPipeline = true. Default state: Disabled.
- Code
PSUseSingleValueFromPipelineParameter- Severity
- warning
This rule detects cmdlet names that use plural nouns instead of singular nouns. Default state: Enabled.
- Code
PSUseSingularNouns- Severity
- warning
This rule detects manual declarations of WhatIf and Confirm parameters in functions and cmdlets. Rather than manually declaring these parameters, you should use the CmdletBinding attribute with SupportsShouldProcess as a named argument. Default state: Always enabled.
- Code
PSUseSupportsShouldProcess- Severity
- warning
This rule detects when module manifests use wildcards ('*') or null ($null) in export fields. To improve module autodiscovery performance, module manifests shouldn't use wildcards or null in the following entries: Default state: Always enabled.
- Code
PSUseToExportFieldsInManifest- Severity
- warning
This rule detects when scriptblocks running in new runspaces reference parent scope variables without the $using: scope modifier. When a scriptblock is intended to run in a new runspace, it can't directly access variables from the parent scope. Default state: Always enabled.
- Code
PSUseUsingScopeModifierInNewRunspaces- Severity
- warning
This rule detects when an about_ help file doesn't use UTF-8 encoding. The rule verifies that help files starting with about_ and ending with .help.txt are saved in UTF-8 encoding. It uses the **CurrentEncoding** property of the **StreamReader** class to check the file's encoding. Default state: Always enabled.
- Code
PSUseUTF8EncodingForHelpFile- Severity
- warning