missing-mandatory-parameter
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”Write-Verbose -Verbose "text"Write-Verbose "text"Write-Verbose -Message "text" -VerboseWrite-Verbose -ErrorAction Stop "text"Write-Verbose -Verbose:$true "text"Write-VerboseWrite-Verbose @args"text" | Write-VerboseJoin-Path -Path aJoin-Path -Resolve aJoin-Path a -ResolveConfiguration
Section titled “Configuration”powershell: lint: rules: missing-mandatory-parameter: warn # off (default), warn, errorEnabled by the presets: powershell/psscriptanalyzer.
Suppress one line with sudsy-disable-next-line missing-mandatory-parameter in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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". |