title: Compare two lists in Powershell
body: <p>I have just started working on powershell. I have two lists of 132 and 134 records each. They have 85 records in common and I want to get the values which are in list1 but not in list2 in a seperate list say list_out1 and the values which are in list2 but not in list1 in another list say list_out2. I finally want to print list_out1 and list_out2. I tried to do as given in <a href="https://stackoverflow.com/questions/19012457/compare-two-list-and-find-names-that-are-in-list-one-and-not-list-two-using-powe">this answer</a> but it is giving me all the values in list1 while trying to print list_out1. Also, I have tried using foreach loop and if condition as below and it is also giving me all the values in list1 to print list_out1.</p>
  
  <pre><code>foreach ($i in $list1)
  {
     if($list2 -notcontains $i) {
        $i
      }
  }
  </code></pre>
  
  <p>I don't know where am I doing wrong. The logic seems to be alright for me. Correct me if I am wrong. </p>