title: Sorting and Comparing Arraylists
body: <p>I'm pretty new to Powershell and have a problem. 
  It seems I can get neither the <code>Compare-Object</code> nor the <code>Sort-Object</code> funtions to work. 
  I got two Arraylists which I fill with 10 objects of type "Table".</p>
  
  <pre><code>#Create Arraylists
  $list1 = new-object System.Collections.ArrayList
  $list2 = new-object System.Collections.ArrayList
  
  
  #Declare Table-Class
  class Table {
      [String] $name
      [Int] $number
  }
  
  
  #Fill list1
  [Int] $i = 0
  while ($i -lt 10) {
      $entry = new-Object Table
      $entry.name = "Name";
      $entry.number = $i;
      $list1.Add($entry)
      $i++
  }
  
  #Fill list2
  [Int] $j = 10
  while ($j -gt 0) {
      $entry = new-Object Table
      $entry.name = "name";
      $entry.number = $j;
      $list2.Add($entry)
      $j--
  }
  </code></pre>
  
  <p>Now I want to compare these two ArrayLists like this:</p>
  
  <p><code>Compare-Object $list1 $list2 | ForEach-Object {$_.InputObject}</code></p>
  
  <p>This doesn't seem to work and I think it's because I'm not really doing anything with the comparison. If someone could help me with the correct Syntax I'd be really happy.
  Anyway, I think this comparison would somehow return a <code>$false</code> boolean.
  If that were true, I'd like to sort <code>$list2</code> by <code>$entry.number</code>.</p>
  
  <p>I'm attempting this like that:</p>
  
  <pre><code>$list2 = $list2 | Sort-Object -Property { $_[1] }
  </code></pre>
  
  <p>But my list doesn't change at all. I already tried several different "solutions" but it seems none of these is a real "solution".</p>
  
  <p>I'd be really glad if someone could help me or at least point me in the right direction.</p>
  
  <hr>
  
  <p>EDIT: For future readers, here is the working syntax:</p>
  
  <pre><code>#sort list by the property number
  $list2 = $list2 | sort-object -Property number
  
  #count differences and if differences greater than 0, do stuff
  [Int] $diff
  $properties = $list1 | Get-Member -MemberType Property | Select-Object -ExpandProperty Name
  
  foreach ($property in $properties) {
      $diff = 0
      $diff = (Compare-Object $list1 $list2 -Property "$property").count
      if ($diff -ne 0) {
          #do stuff
      }
      else {
          #do something else
      }
  }
  </code></pre>