I would like to compare values in two columns in file1.csv with file2.csv, then assigned the matching value to a new column in file1.csv.
ATM, this is the working so far. Simpler format would be ideal.
$report = Import-CSV -Path "C:\report.csv" -Encoding UTF8
$reference = Import-CSV -Path "C:\team.csv" -Encoding UTF8
foreach ($team1 in $report){
$matched = $false
foreach ($team2 in $reference){
$obj = "" | select "Type","Setup","Responsible","Team","Main"
if($team1.'Setup' -like "*$($team2.'Main')*"){
$matchCounter++
$matched = $true
$obj.'Type' = $team1.'Type'
$obj.'Setup' = $team1.'Setup'
$obj.'Responsible' = $team1.'Responsible'
$obj.'Team' = $team2.'Team'
$obj | Export-Csv -Path "C:\Output.csv" -Append -NoTypeInformation -Encoding
UTF8
}
}
}
This is what the files like;
file1
type setup responsible
---- ------- -----------
y master fin susan
y sensei kuno peter
y sensei jon peter
y junior jumo
file2
main team
---- -----
master sa1
sensei sr2
jumo st6
desired file3
type setup responsible team
---- ------- ----------- -----
y master fin susan sa1
y sensei kuno peter sr2
y sensei jon peter sr2
y junior jumo st6
What I would like to achieve is column setup
and responsible
(file1) to be compared to main
column (file2) and get its adjacent team
. Atm, im not sure how to go about skipping cells in column1 with no reference in file2, but existed in column2. Also, to compare only the first character of setup
in file1 with file2.