The equality test is not so simple.
Note that 'a' -eq 'A'returns true. This means that PowerShell does more than just invoke Equals.
Further for your objects it Equalsis caused as expected.
Add-Type -TypeDefinition @"
using System;
public class X {
public string Property;
public X(string s) {
Property = s;
}
public override bool Equals(object o) {
System.Console.WriteLine("equals on {0}", Property);
return Property == ((X)o).Property;
}
public override int GetHashCode() { return 20; }
}
"@
$o1 = New-Object X 'a'
$o2 = New-Object X 'A'
$o1 -eq $o2
, PowerShell . , , .
'1' -eq 1 .