| description | Avoid using null or empty HelpMessage parameter attribute |
|---|---|
| ms.date | 07/21/2026 |
| ms.topic | reference |
| title | AvoidNullOrEmptyHelpMessageAttribute |
Severity Level: Warning
Default state: Always enabled
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.
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
}Function GoodFuncHelpMessage
{
Param(
[Parameter(HelpMessage='This is helpful')]
[String]
$Param
)
$Param
}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.
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
)
}