PowerShell Boolean Comparison

This topic contains 3 replies, has 4 voices, and was last updated by  Stephanos Constantinou 3 months ago.

  • Author
  • #98994

    Wayne Hoggett

    Quick question, what does the community prefer or consider a best practice/community standard for checking if something is not true? i.e. boolean comparison

    if (-Not (Test-Path "C:\Temp"))


    if (!(Test-Path "C:\Temp"))


    if ((Test-Path "C:\Temp") -eq $false)

    OR something else?

  • #99004

    Dave Brannan

    I personally do the first as I find it easier to read and for others to understand what the code is testing for.


  • #99028

    Joel Sallow

    I would also opt for the first, but the second isn't bad either. They're pretty much equivalent, but someone unfamiliar with programming may find the first easier to understand.

  • #99154

    I am also going for the first one. It gives others better understanding. If the script is only for myself, I might use the second option as well.

You must be logged in to reply to this topic.