以下是我在 2 csv 中的資料
CSV_1
"Username","UserCreationStatus","GroupAdditionStatus"
"WA92J4063641OAD","Success","Success"
CSV_2
"GroupName","GroupCreationStatus"
"WA92GRP-ADAdminAccount-CAP-OAD","Already exist"
我需要將它們合并到單個 csv 檔案中,如下所示
"Username","UserCreationStatus","GroupAdditionStatus","GroupName","GroupCreationStatus"
"WA92J4063641OAD","Success","Success","WA92GRP-ADAdminAccount-CAP-OAD","Already exist"
我試過下面的代碼
Get-ChildItem -Path $RootPath -Filter *.csv | Select-Object * | Import-Csv | Export-Csv $RootPath\merged.csv -NoTypeInformation -Append
但低于錯誤
Import-Csv : You must specify either the -Path or -LiteralPath parameters, but not both.
請讓我知道這里有什么問題
uj5u.com熱心網友回復:
你可以這樣做。
它不起作用,但顯示了邏輯。
如果您有任何問題,請告訴我。
$CSV1 = ".\first.csv"
$CSV2 = ".\second.csv"
$NewCSV = ".\new.csv"
$Data1 = Get-Content -Path $CSV1
$Data2 = Get-Content -Path $CSV2
foreach ($Line in $CSV1)
{
Add-Content -Value "$($Line),$($CSV2[$index])" -Path $NewCSV
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/348792.html
