Skip to content

AvoidDefaultValueForMandatoryParameter mistakenly reported. #1623

Open
@danielniccoli

Description

@danielniccoli

The following code makes PSScriptAnalyzer report AvoidDefaultValueForMandatoryParameter. For one parameter set, the parameter is optional, so having a default value may be desired and should not throw a warning.

function Test
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory, ParameterSetName = "Mandatory")]
        [Parameter(ParameterSetName = "Optional")]
        $Parameter1 = 'default Value'
    )
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions