Edit

UseSingularNouns

Severity Level: Warning

Default state: Enabled

Description

This rule detects cmdlet names that use plural nouns instead of singular nouns.

PowerShell best practices require that cmdlets use singular nouns, not plurals. You can use the NounAllowList parameter to exclude specific nouns from this rule, or suppress the rule for individual functions using SuppressMessageAttribute. If a violation is found, change the plural noun to its singular form.

For example:

function Get-Elements {
    [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', 'Get-Elements')]
    Param()
}

Example

Noncompliant

function Get-Files
{
    ...
}

Compliant

function Get-File
{
    ...
}

Configure rule

Rules = @{
    PSUseSingularNouns = @{
        Enable           = $true
        NounAllowList    = 'Data', 'Windows', 'Foos'
    }
}

Parameters

Enable

This parameter controls whether ScriptAnalyzer checks the code against this rule. It accepts a boolean value. To disable this rule, set this parameter to $false. The default value is $true.

NounAllowList

This parameter specifies which command nouns to exclude from this rule. It accepts a string array. Both Data and Windows are common false positives and excluded by default. Default values are 'Data' and 'Windows'.