title: Compare-Object is returning the wrong value
body: <p>I'm working on a PowerShell script and the <code>Compare-Object</code> cmdlet is not returning what I expect. I won't put the whole script here, but this is the general idea:</p>
  
  <pre><code>$knownFiles = Import-Csv -Path "C:\knownfiles.csv"
  $currentFiles = Get-ChildItem -Path "\\file\share"
  $knownFileObject = $knownFiles |
                     Select-Object -Property Name, Length, LastWriteTimeUTC |
                     Sort-Object -Property Name
  $currentFileObject = $currentFiles |
                       Select-Object -Property Name, Length, LastWriteTimeUTC |
                       Sort-Object -Property Name
  </code></pre>
  
  <p>So now, I have two sorted PSCustomObjects containing the Names, Length and Last Write Time of a set of files. Here's what I can't figure out.</p>
  
  <p>If the objects are identical, <code>Compare-Object</code> returns nothing, as expected. However, using the example below:</p>
  
  <p><code>$knownFileObject</code> looks like this:</p>
  
  <pre>
  Name          Length     LastWriteTimeUtc
  ----          ------     ----------------
  file1.dat     38988     1/1/2018 8:04:57 AM
  file2.dat     7182      1/2/2017 8:03:24 AM
  file4.dat     1026      1/3/2017 8:04:20 AM
  file5.dat     25137     1/3/2018 8:07:51 AM
  </pre>
  
  <p><code>$currentFileObject</code> looks like this:</p>
  
  <pre>
  Name          Length     LastWriteTimeUtc
  ----          ------     ----------------
  file1.dat     38988     1/1/2018 8:04:57 AM
  file2.dat     7182      1/2/2017 8:03:24 AM
  file3.dat     1026      1/2/2018 8:04:30 AM
  file4.dat     1026      1/3/2017 8:04:20 AM
  file5.dat     25137     1/3/2018 8:07:51 AM
  </pre>
  
  <p>If I run</p>
  
  <pre><code>Compare-Object -ReferenceObject $knownFileObject -DifferenceObject $currentFileObject
  </code></pre>
  
  <p>it will return this:</p>
  
  <pre>
  InputObject                                                            SideIndicator
  -----------                                                            -------------
  @{Name=file5.dat; Length=25137; LastWriteTimeUtc=1/3/2018 8:07:51 AM}  =>
  </pre>
  
  <p>It definitely detects that there is a difference between the two objects, but it always just returns the last row, instead of the actual record that's different. If there are two changed files, it returns the last two rows. If I add a <code>"-property Name"</code> to the <code>Compare-Object</code>, it returns the correct file name, but I also need to look for differences in size and write time. I can use <code>Export-Csv</code> to write both of the objects back out to a file, then run <code>Compare-Object</code> on the <code>Get-Content</code> of those files, and that works great, but I don't want to have to write two files to disk, as this job will be running hundreds of times per minute on different folders.</p>
  
  <p><strong>EDIT:</strong> Per one of the suggestions, I've also tried <code>Compare-Object ... -Property Name, Length, LastWriteTimeUtc</code>, and when I do that, it returns every item in both objects, or a 100% mismatch.</p>
  
  <p>What am I doing wrong?</p>