1

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.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
mkrouse
  • 277
  • 2
  • 4
  • 11

2 Answers2

4

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
Kevin_
  • 2,916
  • 3
  • 19
  • 18
ravikanth
  • 24,922
  • 4
  • 60
  • 60
1

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.

Community
  • 1
  • 1
Eris
  • 7,378
  • 1
  • 30
  • 45