Monday, July 30, 2012

Set Boolean Switches

I was excited when I read in the Get-Help about_commonParameters article that one can set true or false on a switch parameter.  Previously, I thought that it was false unless specified.  Now I see that if one adds a colon and a Boolean variable, then the switch can be set to false even when specified.  It looks like this:

restart-computer -whatif:$false

There were several cases when I didn't know whether I would need a switch or not, and I had convoluted code to form an expression which I would then invoke.  Now it is much cleaner.

So reading those long about_* articles does have its benefits!

No comments:

Post a Comment