Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Credential Attribute Declaration

The Credential attribute is an optional attribute that can be used with credential parameters of type PSCredential so that a string can also be passed as an argument to the parameter. When this attribute is added to a parameter declaration, Windows PowerShell converts the string input into a PSCredential object. For example, the Get-Credential cmdlet uses this attribute to have Windows PowerShell generate the PSCredential object that is returned by the cmdlet.

[Credential]

  • Typically this attribute is used by parameters of type PSCredential so that a string can also be passed as an argument to the parameter. When a PSCredential object is passed to the parameter, Windows PowerShell does nothing.

  • When creating the PSCredential object, Windows PowerShell uses the current Host to display the appropriate prompts to the user. For example, the default Host displays a prompt for a user name and password when this attribute is used. However, if a custom host is being used that defines a different prompt then that prompt would be displayed.

  • This attribute is used with the Parameter attribute. For more information about that attribute, see Parameter Attribute Declaration.

  • The credential attribute is defined by the CredentialAttribute class.



Show:
© 2015 Microsoft