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 is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in
Dockerfiles.
| Property | Value |
|---|
| Severity | Warning |
| Category | PSScriptAnalyzer |
| Auto-fix | No |
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
function Test
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
$Parameter1 = 'default Value'
)
}
Correct code
function Test
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
$Parameter1
)
}
Source
This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for
AvoidDefaultValueForMandatoryParameter,
licensed under CC BY 4.0.