Welcome › Forums › General PowerShell Q&A › Marking Parameter as Flag Value
Hi, how do I mark a parameter as a flag? I use the Parameter decorator right now, but if I give the variable a type of bool this means I have to specify $true or $false after it.
I'm doing this from C#, but I could not find examples for Psh either.
In PowerShell, you would type this parameter as [switch]. In C# you need to use the SwitchParameter type. 🙂
Thanks for the response Joel. To clarify for anyone reading this later, the parameter's type is SwitchParameter, it's not an annotation. Confused me at first.
As a follow up question, this marks the flag as [[-Name]] instead of [-Name] when using Get-Help. Is there a way to fix this?
Specifying the Position in the [Parameter()] decorator will cause that. Removing the Position will get you [-Name].
Yep. Switch parameters shouldn't declare position anyway, since you can't actually give them a value positionally.