Closed
Description
The documentation does not match the implementation, it appears to be the documentation of an old rule (PSProvideDefaultParameterValue) that has been removed and this one is always quoted in the documentation
See also this discussion around this rule.
I do not understand why the presence of the cmdletbinding attribute influences the rule.
Setting a default value to a mandatory parameter does not make sense in all cases.
From this test :
badfunc
cmdlet BadFunc at command pipeline position 1
Supply values for the following parameters:
Param1:
BadFunc : Cannot validate argument on parameter 'Param1'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
#---
goodfunc2
cmdlet GoodFunc2 at command pipeline position 1
Supply values for the following parameters:
Param1:
GoodFunc2 : Cannot validate argument on parameter 'Param1'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Or this:
$sb={
param (
[Parameter(Mandatory=$true)]
$Param1="String"
)
$param1
}
&$sb
cmdlet at command pipeline position 1
Supply values for the following parameters:
Param1:
Cannot validate argument on parameter 'Param1'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Note that the error message is about cmdlet ...
Maybe the presence of the cmdletbinding attribute is another recommendation: Always Start With CmdletBinding