Click to Rate and Give Feedback
MSDN
MSDN Library
Windows PowerShell
 ParameterAttribute.Mandatory Proper...

  Switch on low bandwidth view
ParameterAttribute.Mandatory Property
Gets and sets a Boolean value that indicates whether the parameter is required when the cmdlet or function is run.


Namespace: System.Management.Automation
Assembly: System.Management.Automation (in system.management.automation.dll)
Dim instance As ParameterAttribute
Dim value As Boolean

value = instance.Mandatory

instance.Mandatory = value
Visual Basic
Public Property Mandatory As Boolean
C#
public bool Mandatory { get; set; }
C++
public:
property bool Mandatory {
    bool get ();
    void set (bool value);
}
J#
/** @property */
public boolean get_Mandatory ()

/** @property */
public void set_Mandatory (boolean value)
JScript
public function get Mandatory () : boolean

public function set Mandatory (value : boolean)

Property Value

A Boolean value that indicates true if the parameter is required when the cmdlet or function is run. If the value is false, the parameter is optional.

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

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

This property is an optional Named parameter of the Parameter attribute. For more information about the declaration syntax that is used to specify the Parameter attribute for cmdlets, see ParameterAttribute Declaration.


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

Development Platforms

Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 7, Windows 2008 R2

Target Platforms

Windows Server 2008, Windows Server 2003, Windows Vista, Windows XP, Windows 7, Windows 2008 R2
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker