What I am trying to do is grab two csv files and compare the information and pull the data into a text file or Convertto-html. I would like to match or -IncludeEqual the id's and then out-file the id's that match with the site name also... if that makes sense. This is what I have so far:
master.csv:first, last, ID, site
bob, smith, XXXX, dallas
test.csv: role,ID
admin, XXXX
---------------------------------------------------------------------------------------------
$file1 = import-csv -Path "C:\master.csv" | Select-Object ID, site
$file2 = import-csv -Path "C:\test.csv" | Select-Object ID
$Compared = Compare-Object -referenceObject $file2 -differenceObject $file1 -property ID -IncludeEqual
Foreach ($i in $Compared)
{
$Site = $i."site"
$ID = $i."ID"
$Si = $i.SideIndicator
$c++
If($si -eq "==")
{
"[$c] The IDs match $Si $Site ------ $ID" | Out-File C:\temp\test123.txt -Append
}
If($si -eq "<=")
{
"[$c] ID is not in test.csv $Si $Site ------ $ID" | Out-File C:\temp\test123.txt -Append
}
If($si -eq "=>")
{
"[$c]ID is not in master.csv $Si $Site ------ $ID" | Out-File C:\temp\test123.txt -Append
}
}
---------------------------------------------------------------------------------------------
Ultimately I just want to list the matching IDs with the site name next the ids.
EXAMPLE
master.csv columns: first, last, ID, site
Bob, Smith, XXXX, Dallas
Joe, Wilson, DDDD,Chicago
Steven, Watkins, CCCC,Boston
Robert, Harris, WWWW, New York
test.csv columns: role, ID
admin,AAAA
user,BBBB
blah,XXXX
blah2,CCCC
OUTPUT: ID,site
XXXX,Dallas
CCCC,Boston
---------------------------------------------------------------------------------------------
Thank you very much in advance!