ParameterAttribute Class
TOC
Collapse the table of content
Expand the table of content

ParameterAttribute Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Defines the Parameter attribute that is used to identify a cmdlet or function parameter. For more information about the syntax and parameters used to declare the Parameter attribute for cmdlets, see ParameterAttribute Declaration.

Namespace:   System.Management.Automation
Assembly:  System.Management.Automation (in System.Management.Automation.dll)


<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field,
	AllowMultiple := True)>
Public NotInheritable Class ParameterAttribute
	Inherits ParsingBaseAttribute

NameDescription
System_CAPS_pubmethodParameterAttribute()

Constructs a ParameterAttribute object. For more information about the declaration syntax that is used to specify the Parameter attribute for cmdlets, see Parameter Attribute Declaration.

NameDescription
System_CAPS_pubpropertyDontShow

Indicates that this parameter should not be shown to the user in this like intellisense. This is primarily to be used in functions that are implementing the logic for dynamic keywords.

System_CAPS_pubpropertyHelpMessage

Gets and sets a short description of the parameter.

System_CAPS_pubpropertyHelpMessageBaseName

Gets and sets the name of the location in which the resource identifiers reside. For example, this property gets or sets the name of resource assembly that contains Help messages for localization.

System_CAPS_pubpropertyHelpMessageResourceId

Gets and sets the resource identifier for the Help message for the parameter.

System_CAPS_pubpropertyMandatory

Gets and sets a Boolean value that indicates whether the parameter is required when the cmdlet or function is run.

System_CAPS_pubpropertyParameterSetName

Gets and sets the name of the parameter set to which this parameter belongs.

System_CAPS_pubpropertyPosition

Gets and sets the position of the parameter in the command-line string.

System_CAPS_pubpropertyTypeId

(Inherited from Attribute.)

System_CAPS_pubpropertyValueFromPipeline

Gets and sets a Boolean value that indicates whether the parameter can take values from incoming pipeline objects.

System_CAPS_pubpropertyValueFromPipelineByPropertyName

Gets and sets a Boolean value that indicates that the parameter can take values from a property of the incoming pipeline object that has the same name as this parameter. For example, if the name of the cmdlet or function parameter is userName, the parameter can take values from the userName property of incoming objects.

System_CAPS_pubpropertyValueFromRemainingArguments

Gets and sets a Boolean value that indicates whether the cmdlet parameter accepts all the remaining command-line arguments that are associated with this parameter.

NameDescription
System_CAPS_pubmethodEquals(Object)

(Inherited from Attribute.)

System_CAPS_pubmethodGetHashCode()

(Inherited from Attribute.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodIsDefaultAttribute()

(Inherited from Attribute.)

System_CAPS_pubmethodMatch(Object)

(Inherited from Attribute.)

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_pubfieldSystem_CAPS_staticAllParameterSets

The parameter set that is used for all the parameters that do not belong to a specific parameter set. To specify a parameter set, see the ParameterSetName property.

For more information about the syntax and parameters used to declare the Parameter attribute for functions, see about_Functions_Advanced_Parameters in the Microsoft TechNet library.

Do not declare parameters that have the following parameter names. Windows PowerShell adds these parameters to cmdlets in order to provide a consistent user experience across all cmdlets.

  • Debug

  • ErrorAction

  • ErrorVariable

  • OutBuffer

  • OutVariable

  • Verbose

  • WarningAction

  • WarningVariable

  • Confirm

  • WhatIf

  • UseTransaction

For more information about about parameter names, see Cmdlet Parameter Names.

This example shows how the Parameter attribute is used to declare a mandatory parameter.

[Parameter(Position = 0, Mandatory = true)]
public string UserName
{
  get { return userName; }
  set { userName = value; }
}
private string userName;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top

Community Additions

ADD
Show:
© 2016 Microsoft