Using Windows PowerShell as an IT Pro – Part 17
In my last post I looked at some Comparison Operators. Now I will examine some more Comparison Operators.Greater than and Less than operators
The greater than operator (-gt) returns a value of TRUE or the matches when one or more of the input values is greater than the specified pattern. The less than operator (-lt) returns a value of TRUE or the matches when one or more of the input values is less than the specified pattern. When the ‘or equals to’ operators (-ge, -le) are used, they also compare to see if the value is equal to the specified pattern.
The following examples show the effects of these operators.
8 -gt 7

8 -ge 8

"c" -lt "a"

"a" -le "c"

1, 2, 3 -le 2

Containment Operators
The containment operators (-contains and -notcontains) are similar to the equality operators. However, the containment operators always return a Boolean value, even when the input is a collection.
Also, unlike the equality operators, the containment operators return a value as soon as they detect the first match. The equality operators evaluate all input and then return all the matches in the collection. In a very large collection, the -contains operator returns results quicker than the equal to operator. The following examples show the effect of the -contains operator.
1, 2, 3 -contains 2

"PowerShell" -contains "Shell"

"Windows", "PowerShell" -notcontains "Shell"

In my next post we will finish looking at Comparison Operators.
No comments:
Post a Comment