Update csv records from another csv

Hello,

I got a task to populate CSV data from another CSV using powershell…

CSV2 (mentioned below) needs to updated for UUID and Asset ID by matching with product code from CSV1.

Unique UUID and asset ID must be updated for matched product code only depending on how many UUID and Asset ID available for each product code.

for example, CSV1 has two UUID’s available for product code HP1023 whereas CSV2 has four records in it. in that case, only two records should be updated and other should left blank.

CSV1
[pre]
Code UUID Asset
HP1023 MNY07789-D112-E34C-B41D-4ACFB442B60P 23160
HP1023 ABC07789-D112-E34C-B41D-4ACFB442B65D 23145
HP2190 XYZ07789-D112-E34C-B41D-4ACFB442B65E 23146

[/pre]

CSV2
[pre]
Code UUID Asset Tag
HP2190
HP1023
HP1023
HP1023
DL1721
HP2190
HP2190
HP1023
[/pre]

below function just fills all the matching records based on product code…Any help would be appreciated…

[pre]
function Update-SysDta
{
$csv1 = Import-Csv ‘.\001.csv’
$csv2 = Import-Csv ‘.\002.csv’

foreach($record in $csv2){

 $sysUID = ($csv1 | where {$_.code -eq $record.code}).UUID
 $record.UUID = $sysUID 

 $SysAT = ($csv1 | where {$_.code -eq $record.code}).Asset
 $record.'Asset Tag'=$SysAT

  
} Return, $csv2

}

Update-SysDta
[/pre]

This looks like the same post below…

https://powershell.org/forums/topic/update-csv-column-by-input-from-another-csv/

https://gist.github.com/kpatnayakuni/ba1d1ec656a7de85d41d6bc31f9e9210

Thanks Kiran for response...but this one has different requirement from other...can you please help me with this one?

"This looks like the same post below…

Update CSV column by input from another csv "
<iframe class="wp-embedded-content" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" title="" src="https://powershell.org/forums/topic/update-csv-column-by-input-from-another-csv/embed/#?secret=mFmEPtMC4E" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" sandbox="allow-scripts" data-secret="mFmEPtMC4E" data-mce-fragment="1"></iframe>Please note, this is different request....can you help me this please?

https://gist.github.com/kpatnayakuni/582fa08af9998afefc9cedf38e25e931