Multiple powershell switch parameters – can it be optimized?

Question:

I am trying to write a simple wrapper that accept one parameter for the output.
This is how it looks now

Clearly this could be optimize but I am struggling to wrap my head around on how I can achieve it .Is there some easy way to ensure only single parameter is accepted and used without resorting to multiple elseif statements?
Also I would like to provide array of paramters instead doing it the way it is done at the moment.

Answer:

Probably not the most elegant solution, but using parametersets makes powershell do some of the work for you:

This example will error out if you don’t provide one of the switches, but you could probably provide an extra switch that does nothing or errors more gracefully if you want to account for that case…

Source:

Multiple powershell switch parameters – can it be optimized? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply