title: PowerShell - How to tell if two objects are identical
body: <p>Let's say you have two objects that are identical (meaning they have the same properties and the same values respectively). </p>
  
  <p>How do you test for equality?</p>
  
  <p><strong>Example</strong></p>
  
  <p><code>$obj1</code> &amp; <code>$obj2</code> are identical</p>
  
  <p><a href="https://i.stack.imgur.com/8pPpu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8pPpu.png" alt="enter image description here"></a></p>
  
  <p>Here's what I've tried:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>This is <strong>not</strong> identical</p>
  
  <p><a href="https://i.stack.imgur.com/QFlHc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QFlHc.png" alt="enter image description here"></a></p>