> ## Documentation Index
> Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt
> Use this file to discover all available pages before exploring further.

# powershell/PSAvoidDefaultValueForMandatoryParameter

> Avoid Default Value For Mandatory Parameter

`powershell/PSAvoidDefaultValueForMandatoryParameter` is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in
Dockerfiles.

| Property | Value |
| - | - |
| Severity | Warning |
| Category | PSScriptAnalyzer |
| Default | Disabled in tally |
| Auto-fix | No |

> [!NOTE]
>
> tally disables this rule by default for Dockerfile `RUN` snippets because a `RUN` executes
> statements inline rather than defining cmdlets, parameters, or modules with external callers. Re-enable it with
> `include = ["powershell/PSAvoidDefaultValueForMandatoryParameter"]` or by setting
> `rules.powershell.PSAvoidDefaultValueForMandatoryParameter.severity = "warning"` in `.tally.toml`.

## Description

Mandatory parameters should not have a default value because there is no scenario where the default
can be used. PowerShell prompts for a value if the parameter value is not specified when calling the
function.

## Examples

### Problematic code

```powershell theme={null}
function Test
{

    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        $Parameter1 = 'default Value'
    )
}
```

### Correct code

```powershell theme={null}
function Test
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        $Parameter1
    )
}
```

## Source

This rule documentation is adapted from Microsoft's PSScriptAnalyzer documentation for
[AvoidDefaultValueForMandatoryParameter](https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/blob/main/reference/docs-conceptual/PSScriptAnalyzer/Rules/AvoidDefaultValueForMandatoryParameter.md),
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).


## Related topics

- [powershell/PSAvoidDefaultValueSwitchParameter](https://tally.wharflab.com/rules/powershell/PSAvoidDefaultValueSwitchParameter.md)
- [powershell/PSDSCUseIdenticalMandatoryParametersForDSC](https://tally.wharflab.com/rules/powershell/PSDSCUseIdenticalMandatoryParametersForDSC.md)
- [powershell/PSAvoidUsingPositionalParameters](https://tally.wharflab.com/rules/powershell/PSAvoidUsingPositionalParameters.md)
- [powershell/PSAvoidLongLines](https://tally.wharflab.com/rules/powershell/PSAvoidLongLines.md)
- [powershell/PSAvoidExclaimOperator](https://tally.wharflab.com/rules/powershell/PSAvoidExclaimOperator.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.