Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Comparison operators work differently with scalars and collections

See

help about_Comparison_Operators

   When the input to an operator is a scalar value, comparison operators
   return a Boolean value. When the input is a collection of values, the
   comparison operators return any matching values. If there are no matches
   in a collection, comparison operators do not return anything.

   The exceptions are the containment operators (-Contains, -NotContains),
   the In operators (-In, -NotIn), and the type operators (-Is, -IsNot),
   which always return a Boolean value.

Comparison operators applied to collections is a very useful feature when used properly. But how this actually works is not always obvious. It may be a trap.

For example, the comparison like this

    $object -eq $value

is not a safe way to test that $object is equal to $value if an object may be a collection as well. See the tests.

Scripts