PowerShell Boolean Comparison

Welcome Forums General PowerShell Q&A PowerShell Boolean Comparison

This topic contains 3 replies, has 4 voices, and was last updated by

 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #98994

    Participant
    Points: 0
    Rank: Member

    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"))

    OR

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

    OR

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

    OR something else?

  • #99004

    Participant
    Points: 0
    Rank: Member

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

    Dave.

  • #99028

    Participant
    Points: 37
    Helping Hand
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘PowerShell Boolean Comparison’ is closed to new replies.