Compare 2 Text Files and Output only matches to a third text file

Hi

This is what I am trying do to compare 2 text file Old.txt and New.txt that has a few names, just need to output the names that are on both the file to a file called duplicate.txt below is what I am running

compare-object (get-content Old.txt) (get-content New.txt) | Out-File duplicate.txt

Here is the problem the file duplicate.txt show all the names that are on the file Old.txt… I have also made sure that only one name is common on both file.

Could someone please help and tell me what I am doing wrong.

Thanks !!
Preenesh

Figured it out… Thanks !!

Here it is in case someone is interested.

$oldlist = get-content old.txt
get-content New.txt | where {$oldlist -contains $_} | Out-File duplicate.txt

Thanks !!
Preenesh