February 2019
Intermediate to advanced
626 pages
15h 51m
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 behaviour 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