I have two txt files. Both contain a list of usernames:
List 1:
user1
user2
user3
List 2:
user1
user2
user7
I want to compare these two lists. I want to know which users do not exist in both lists. So the output in this case should be a this list:
Endlist:
user3
user7
This is my code:
$list1 = get-content -Path "C:\list1.txt"
$list2 = get-content -Path "C:\list2.txt"
$endlist = foreach ($item in $list1)
{
if ($item -notmatch $list2)
{
[PSCustomObject]@{
Name = $item
}
}
$endlist |Out-file "C:\endlist.txt"
What am I doing wrong?