A question recently came up asking why the -eq operator doesn’t work for two different (but equal) SecureStrings.
By default, almost all environments (the .NET Framework included) test if two things are exactly the same – that they are stored in the same place in memory. This is called reference equality.
[D:\documents\WindowsPowerShell]
PS:14 > $test = Read-Host -AsSecureString
****
[D:\documents\WindowsPowerShell]
PS:15 > [Object]::ReferenceEquals($test, $test)
True
[D:\documents\WindowsPowerShell]
PS:16 > $test -eq $test
True
That’s not usually what people want, so each individual type of object is (optionally) responsible for supporting a value-based equality test. They do this by implementing interfaces (software contracts) called IComparable and / or IEquatable:

