Other than the obvious reversal of the parameter order, what is the difference between the -Contains
operator and PowerShell 3.0's new -In
operator?
In PowerShell, the contains operator, doesn't do substring comparison. But instead, it's a collection operator. This means that it will test if a collection contains the matching value. It can't be used to find a character or substring inside a string.
% is an alias for the ForEach-Object cmdlet. An alias is just another name by which you can reference a cmdlet or function.
-gt. Greater than. -ge. Greater than or equal. You don't need an if statement to test the result of a comparison operation.
The ampersand tells PowerShell to execute the scriptblock expression. In essence, it's telling PowerShell that the stuff between the curly braces is code and to run it as code. Passing Arguments to Scriptblocks. Like functions, you can pass "parameters" to scriptblocks also known as arguments.
In short, there is no difference that you haven't already described.
The difference is which value is on the left vs. the right side:
$arr = @(4,5,6)
$arr -contains 5
5 -in $arr
The other difference is that -in
was introduced in PowerShell 3.0, so it won't work on earlier versions.
It's mostly a style thing; use the one that feels more natural for a specific situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With