October 2017
Intermediate to advanced
440 pages
11h 47m
English
When comparison operators are used with scalar values (a single item as opposed to an array), the comparison will result in true or false.
When used with an array or collection, the result of the comparison is all matching elements, for example:
1, $null -ne $null # Returns 1 1, 2, 3, 4 -ge 3 # Returns 3, 4 'one', 'two', 'three' -like '*e*' # Returns one and three
This behavior may be problematic if a comparison is used to test whether or not a variable holding an array exists. In the following example, -eq is used to test that a value has been assigned to a variable called array:
$array = 1, 2
if ($array -eq $null) { Write-Host 'Variable not set' }
This test is apparently valid as long as the array does ...
Read now
Unlock full access