Reputation: 277
This is what I have but its not correct.
(Get-Content C:\Users\U0146121\Desktop\Output.txt) |
ForEach-Object {
Compare-Object -referenceobject $_ -DifferenceObject $(get-content C:\Users\U0146121\Desktop\New folder\filenames.txt) -IncludeEqual
}
I want to compare the current line and see if it is in the filenames.txt If it is then write the name to a new txt file.
Upvotes: 1
Views: 752
Reputation: 7638
This looks like similar to Comparing two arrays & get the values which are not common
Drop each file's contents in a collection $Ref = (Get-Content $origFile); $New = (Get-Content $NewFile);
. Make sure both lists contain the same level of path references (absolute paths vs relative with same depth). Then compare the two collection objects.
Upvotes: 1
Reputation: 25800
You don't need the loop.
Compare-Object -ReferenceObject (Get-Content .\Two.txt) -DifferenceObject (Get-Content .\One.txt) -IncludeEq
ual | Where {$_.SideIndicator -eq '=='} | Select -ExpandProperty InputObject | Out-file C:\same.txt
Upvotes: 4