The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

PowerShell: be careful when passing other bool values than $True and $False around

Posted by jpluimers on 2014/10/30

PowerShell does some powerful conversions.

Always be aware of that, especially when using booleans. For instance: strings are always TRUE, and $ inside strings are not always evaluated, and often people you define their own string to boolean conversions.

It is better to use the automatic variables $True and $False when you really want to make something is TRUE or FALSE.

Read Boolean Values and Operators – Windows PowerShell Blog – Site Home – MSDN Blogs why.

Oh and don’t forget to turn Strict-Mode on to warn for uninitialized variables and other stuff (as of PowerShell version 2; use Set-PsDebug -strict if you are still in PowerShell version 1)

–jeroen

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.