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 this answer 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.
foreach ($i in $list1){ if($list2 -notcontains $i) { $i }}
I don't know where am I doing wrong. The logic seems to be alright for me. Correct me if I am wrong.