Author Posts

June 29, 2015 at 11:52 am

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?


June 29, 2015 at 11:56 am

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.

June 29, 2015 at 12:03 pm

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

Thanks Don