Hi,
Hop this works for you.
#Combin 1.csv and 2.csv into 3.csv
$FilePath1 = "D:\1.csv"
$FilePath2 = "D:\2.csv"
$FilePath3 = "D:\3.csv"
$users = Import-Csv -Path $FilePath1
$properties = ($users|Get-Member -MemberType NoteProperty)
$newuser=@()
Import-Csv -Path $FilePath2|ForEach-Object{
foreach($user in $users){
if($_.mailaddress -eq $user.mailaddress){
foreach($property in $properties){
if($property.Name -ne "mailaddress"){
$_ | Add-Member -NotePropertyName $property.Name -NotePropertyValue $user.($property.Name)}
}
}
}
$newuser +=$_
}
$newuser|Export-Csv -Path $FilePath3 -NoTypeInformation
Best Regards,
Ian
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.