Using [switch] parameter and mandatory=$false together?

This topic contains 2 replies, has 2 voices, and was last updated by  I Am Sir Ask Alot 2 years, 12 months ago.

  • Author
  • #26932

    I Am Sir Ask Alot

    Here is an excerpt from my script:

    [Parameter(Mandatory = $false)]

    Do I need to do this, or does using the [switch] method basically make the "Mandatory=$false" attribute obsolete since using switch is basically telling it using the parameter would equal true, or not using it would make it false?


  • #26933

    Don Jones

    It doesn't "automatically" make Mandatory=$false, but Mandatory=$false is the default for all parameters (never a reason to specify it, really), and Mandatory=$true is incompatible with [switch] from a functional perspective.

  • #26934

    I Am Sir Ask Alot

    Okay, I thought $false was the default, but couldn't recall.

    Thanks Don

You must be logged in to reply to this topic.