Welcome › Forums › General PowerShell Q&A › PowerShell Boolean Comparison
This topic contains 3 replies, has 4 voices, and was last updated by
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?
I personally do the first as I find it easier to read and for others to understand what the code is testing for.
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.
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.