Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SwitchParameter Structure

 

Published: June 10, 2016

Updated: June 10, 2016

Applies To: Windows PowerShell

Defines a type of parameter that is evaluated based on its presence on the command line. Cmdlets and functions can define switch parameters that are evaluated by the Windows PowerShell runtime when the parameters of the command are bound.

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

Public Structure SwitchParameter

NameDescription
System_CAPS_pubmethodSwitchParameter(Boolean)

Initializes a new instance of the SwitchParameter class that identifies whether the switch is present.

NameDescription
System_CAPS_pubpropertyIsPresent

Gets a value that indicates whether the parameter was specified on the command line.

System_CAPS_pubpropertySystem_CAPS_staticPresent

Gets an instance of SwitchParameter object that indicates that the parameter is present.

NameDescription
System_CAPS_pubmethodEquals(Object)

Compares this SwitchParameter object to another object.(Overrides ValueType.Equals(Object).)

System_CAPS_pubmethodGetHashCode()

Gets the hash code for the parameter.(Overrides ValueType.GetHashCode().)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodToBool()

Converts the current SwitchParameter object to a Boolean object.

System_CAPS_pubmethodToString()

Generates a string representation of the current SwitchParameter object.(Overrides ValueType.ToString().)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(Boolean, SwitchParameter)

Compares a Boolean object to a SwitchParameter object and returns true if they resolve to the same value.

System_CAPS_puboperatorSystem_CAPS_staticEquality(SwitchParameter, Boolean)

Compares a SwitchParameter object to a Boolean object and returns true if they resolve to the same value.

System_CAPS_puboperatorSystem_CAPS_staticEquality(SwitchParameter, SwitchParameter)

Compares two SwitchParameter objects and returns true if they resolve to the same value.

System_CAPS_puboperatorSystem_CAPS_staticWidening(Boolean to SwitchParameter)

Casts a Boolean value to a SwitchParameter.

System_CAPS_puboperatorSystem_CAPS_staticWidening(SwitchParameter to Boolean)

Casts a SwitchParameter object to a Boolean object.

System_CAPS_puboperatorSystem_CAPS_staticInequality(Boolean, SwitchParameter)

Compares a Boolean object to a SwitchParameter object and returns true if they resolve to different values.

System_CAPS_puboperatorSystem_CAPS_staticInequality(SwitchParameter, Boolean)

Compares a SwitchParameter object to a Boolean object and returns true if they resolve to different values.

System_CAPS_puboperatorSystem_CAPS_staticInequality(SwitchParameter, SwitchParameter)

Compares two SwitchParameter objects and returns true if they resolve to different values.

A switch parameter is a parameter that may, or may not, be specified when the command is run. If the parameter is specified, the Windows PowerShell runtime resolves its value as true. If the parameter is not specified, which is typically the default, the parameter value is resolved as false.

The following example shows how the declare a parameter of type SwitchParameter.

[Parameter(Position = 1)]
public SwitchParameter GoodBye
{
  get { return goodbye; }
  set { goodbye = value; }
}
private bool goodbye;

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

Show: