【发布时间】:2021-02-05 18:08:51
【问题描述】:
我的目标是能够从 csv1 中获取值并将它们更新为 csv2,其中根据 id 的列值找到匹配项。我可以看到输出值正在更新,但是当我尝试将其导出到 csv 文件时,我得到以下内容...
"Length"
"60"
"60"
"60"
"60"
这里是代码。
$inputCsv = Import-CSV './get_values.csv' -delimiter ","
$updateCsv = Import-CSV './set_values.csv' -delimiter ","
$output = $updateCsv | ForEach-Object {
# Matching value
$id = $_.id
# Row of values found in 2nd file matching value from first file
$rowFound = $inputCsv|Where-object "ID" -EQ $id #
# Columns to update values
if($rowFound -ne $Null -and $rowFound -ne ''){
$_.email = $rowFound.Email
Write-Output $_.email
$_.firstname = $rowFound.FirstName
Write-Output $_.firstname
$_.lastname = $rowFound.LastName
Write-Output $_.lastname
Write-Output "------------------------------------------------------------"
}
}
$output | Export-Csv 'C:\scripts\powershell\output.csv' -NoTypeInformation
我已经尝试过这里的解决方案:Export-CSV exports length but not name
但我无法让它们中的任何一个工作。
【问题讨论】:
标签: powershell