Skip to content

missing-mandatory-parameter

PowerShellcorrectnessno fixdefault: offpowershell/psscriptanalyzer

Reports a call of a cmdlet that gives none of the parameters that every parameter set requires, by name or by position. A -name takes the element after it as its value, so Write-Verbose -Verbose "text" leaves -Message unbound. A command behind a pipe or with a splatted argument is left alone.

PowerShell asks for a missing mandatory parameter at run time and waits for input. In a script or on a server that hangs the run, or fails with an error when there is no host to ask.

To fix, give the parameter by name.

Reported
Write-Verbose -Verbose "text"
Write-Verbose "text"
Write-Verbose -Message "text" -Verbose
Write-Verbose -ErrorAction Stop "text"
Write-Verbose -Verbose:$true "text"
Write-Verbose
Write-Verbose @args
"text" | Write-Verbose
Join-Path -Path a
Join-Path -Resolve a
Join-Path a -Resolve
powershell:
lint:
rules:
missing-mandatory-parameter: warn # off (default), warn, error

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line missing-mandatory-parameter in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
psscriptanalyzer PSUseCmdletCorrectly partial Reads a table of the cmdlets that have a parameter mandatory in every parameter set (generated by scripts/gen_powershell_commands.ps1 from the built-in modules of PowerShell 7.7); the module asks the commands of its host, user functions included. A -name takes the next element as its value, which is how the module reads Write-Verbose -Verbose "x".