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

1 year, 1 month ago.

  • Author
  • #98994

    Topics: 2
    Replies: 1
    Points: 1
    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"))


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


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

    OR something else?

  • #99004

    Topics: 9
    Replies: 18
    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.


  • #99028

    Topics: 2
    Replies: 437
    Points: 877
    Helping Hand
    Rank: Major Contributor

    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

    Topics: 0
    Replies: 4
    Points: 23
    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort