Search Wiki:

UseCredentialAttributeForPSCredentialParameter


TypeName UseCredentialAttributeForPSCredentialParameter
CheckId PS1013
Error-Level Warning
Category Microsoft.PowerShell
Certainty 95%
BreakingChange Non-breaking
Cause A cmdlet parameter of type PSCredential does not have the CredentialAttribute type.
Rule descriptionIf a parameter is of type PSCredential, the parameter must have the Credential attribute. This attribute prompts the user for a user name and/or password when the user does not supply a complete credential for the parameter value.
How to fix violations Add CredentialAttribute to the cmdlet parameter.
When to exclude warnings Do not suppress warnings from this rule.
Related rules UseRecommendedParameterTypes
See also FxCop Rules for Windows PowerShell

Examples


This example violates the rule, because the attribute is missing.
    [Cmdlet("Test", "Credential")]
    public class TestCredentialCommand : PSCmdlet
    {
        [Parameter]
        public PSCredential Credential
        {
            get { return this.credential; }
            set { this.credential = value; }
        }
        // ...
    }

This example complies with the rule.
    [Cmdlet("Test", "Credential")]
    public class WriteStringCommand : PSCmdlet
    {
        [Parameter]
     // The Credential attribute fulfills the requirement.
        [Credential]
        public PSCredential Credential
        {
            get { return this.credential; }
            set { this.credential = value; }
        }
        // ...
    }

Back to FxCop Rules for Windows PowerShell.
Last edited Apr 7 2010 at 4:58 PM  by JuneB, version 2
Updating...
Page view tracker