File1
"FACILITY","FILENAME"
"16","abc.txt"
"16","def.txt"
"12","abc.txt"
"17","def.txt"
"18","abc.txt"
"19","abc.txt"
File2
"FACILITY","FILENAME"
"16","jkl.txt"
"16","abc.txt"
"12","abc.txt"
"17","jkl.txt"
"18","jkl.txt"
"19","jkl.txt"
I'm looking for this output:
"FACILITY","FILENAME"
"16","abc.txt"
"12","abc.txt"
For every FILENAME in File2, I would like to list if the filename is in File1 on a per FACILITY basis. So if there is file qwerty.txt listed next to FACILITY 20 in File1 and it matches a FILENAME in File2 with the filename qwerty.txt on the same line, then spit out the output.
Let's say there is a qwerty.txt file for differing Facilities, I do not want that in my output.
Here is something I've tried but I feel like I've butchered the commands because I don't fully understand them.
$file1 = Import-Csv $scriptPath'\loadedfiles.txt' -Delimiter ','
$file2 = Import-Csv $scriptPath'\filenames.txt' -Delimiter ','
$Header = $file1 | Get-Member | Where-Object -FilterScript {$_.MemberType -eq 'FACILITY'} | Select-Object -ExpandProperty FILENAME
Compare-Object -ReferenceObject $file1 -DifferenceObject $file2 -Property 'FILENAME' -PassThru | Select-Object -Property $Header |
Export-Csv -Path $scriptPath\test.csv -NoTypeInformation
I have seen plenty examples how to compart two lists, but I need to compare one property based on another which is why I'm struggling with just searching google for an answer.