Skip to content

Latest commit

 

History

History
111 lines (86 loc) · 2.72 KB

AvoidNullOrEmptyHelpMessageAttribute.md

File metadata and controls

111 lines (86 loc) · 2.72 KB
description Avoid using null or empty HelpMessage parameter attribute
ms.date 07/21/2026
ms.topic reference
title AvoidNullOrEmptyHelpMessageAttribute

AvoidNullOrEmptyHelpMessageAttribute

Severity Level: Warning

Default state: Always enabled

Description

This rule detects HelpMessage 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.

Using an empty string or null value causes PowerShell to raise an error at runtime. Always provide a descriptive help message that explains the parameter's purpose and expected input to users.

Example

Noncompliant

Function BadFuncEmptyHelpMessageEmpty
{
    Param(
        [Parameter(HelpMessage='')]
        [String]
        $Param
    )

    $Param
}

Function BadFuncEmptyHelpMessageNull
{
    Param(
        [Parameter(HelpMessage=$null)]
        [String]
        $Param
    )

    $Param
}

Function BadFuncEmptyHelpMessageNoAssignment
{
    Param(
        [Parameter(HelpMessage)]
        [String]
        $Param
    )

    $Param
}

Compliant

Function GoodFuncHelpMessage
{
    Param(
        [Parameter(HelpMessage='This is helpful')]
        [String]
        $Param
    )

    $Param
}

Configure rule

This rule is always enabled and isn't configurable. Use one of the following methods to avoid using this rule:

  • 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.

Suppression

As with other rules, you can suppress this rule by adding a suppression attribute to the param block of a function or script. An empty string as the second argument suppresses every violation of the rule in that scope.

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidNullOrEmptyHelpMessageAttribute', '')]

To suppress the rule for a single parameter, pass the parameter name without the leading $ as the second argument. The name isn't case sensitive.

function Test-Script {
    [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidNullOrEmptyHelpMessageAttribute', 'Parameter')]
    param(
        [Parameter(HelpMessage = '')]
        [String]$Parameter
    )
}