concept True in category powershell

appears as: True
Learn Windows PowerShell in a Month of Lunches, Third Edition

This is an excerpt from Manning's book Learn Windows PowerShell in a Month of Lunches, Third Edition.

In computers, a comparison always takes two objects or values and tests their relationship to one another. You might be testing whether they’re equal, or whether one is greater than another, or whether one of them matches a text pattern of some kind. You indicate the kind of relationship you want to test by using a comparison operator. The result of the test is always a Boolean value: True or False. Put another way, either the tested relationship is as you specified, or it isn’t.

  • (5 -gt 10) -or (10 -lt 100) is True, because at least one subexpression is True
  • In addition, the Boolean -not operator reverses True and False. This can be useful when you’re dealing with a variable or a property that already contains True or False, and you want to test for the opposite condition. For example, if you want to test whether a process isn’t responding, you could do the following (you’ll use $__ as a placeholder for a process object):

    $_.Responding -eq $False

    Windows PowerShell defines $False and $True to represent the False and True Boolean values. Another way to write that comparison is as follows:

    -not $_.Responding

    Because Responding normally contains True or False, the -not reverses False to True. If the process isn’t responding (meaning Responding is False), your comparison will return True, indicating that the process is “not responding.” We prefer the second technique because it reads, in English, more like what we’re testing for: “I want to see if the process isn’t responding.” You’ll sometimes see the -not operator abbreviated as an exclamation mark (!).