jeudi 30 novembre 2017

PowerShell - How to tell if two objects are identical

Let's say you have two objects that are identical (meaning they have the same properties and the same values respectively).

How do you test for equality?

Example

$obj1 & $obj2 are identical

enter image description here

Here's what I've tried:

if($obj1 -eq $obj2)
{
    echo 'true'
} else {
    echo 'false'
}
# RETURNS "false"

if(Compare-Object -ReferenceObject $obj1 -DifferenceObject $obj2)
{
    echo 'true'
} else {
    echo 'false'
}
# RETURNS "false"

Aucun commentaire:

Enregistrer un commentaire