> ## 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`.
</Note>

## 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/).
