The -not (or !) operator may be used to negate the expression that follows it.
For example, each of the following returns true:
-not $false -not (Test-Path X:) -not ($true -and $false) !($true -and $false)
Double negatives
The -not operator has an important place, but it is worth rethinking an expression if it injects a double negative. For example, the following expression will return true: -not (1 -ne 1).
The preceding expression is better written using the -eq operator: 1 -eq 1.
The -not operator has an important place, but it is worth rethinking an expression if it injects a double negative. For example, the following expression will return true: -not (1 -ne 1).
The preceding expression is better written using the -eq operator: 1 -eq 1.