# Update csv records from another csv

**URL:** <https://forums.powershell.org/t/update-csv-records-from-another-csv/11926>\
**Category:** PowerShell Help\
**Created:** [January 18, 2019, 10:10am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926 "2019-01-18T10:10:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachin-ghagare](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sachin-ghagare](https://forums.powershell.org/u/sachin-ghagare)\
**Post date:** [January 18, 2019, 10:10am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/1 "2019-01-18T10:10:30Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [January 18, 2019, 10:15am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/2 "2019-01-18T10:15:51Z")

</div>

This looks like the same post below…

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

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

---

<div class="post-metadata">

**Author:** ![sachin-ghagare](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sachin-ghagare](https://forums.powershell.org/u/sachin-ghagare)\
**Post date:** [January 18, 2019, 11:57am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/3 "2019-01-18T11:57:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sachin-ghagare](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@sachin-ghagare](https://forums.powershell.org/u/sachin-ghagare)\
**Post date:** [January 21, 2019, 2:06am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/4 "2019-01-21T02:06:19Z")

</div>

"This looks like the same post below…

> [Update CSV column by input from another csv "](https://powershell.org/forums/topic/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?

---

<div class="post-metadata">

**Author:** ![kpatnayakuni](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kpatnayakuni/32/19_2.png) [@kpatnayakuni](https://forums.powershell.org/u/kpatnayakuni)\
**Post date:** [January 21, 2019, 9:53am UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/5 "2019-01-21T09:53:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/update-csv-records-from-another-csv/11926/6 "2024-05-16T20:34:05Z")

</div>


