我正在尝试创建一个报告,以从中获取信息 两个单独的cmd,并希望将它们合并/附加到一个.csv文件中。下面是Final.csv文件中所需的示例。
File1.csv
:
Col1 ---- apple orange
File2.csv
:
Col2 ---- pears dogs
Final.csv
:
Col1 Col2 ---- ---- apple pears orange dogs
到目前为止我尝试过的代码是:
Import-Csv -Path '.\FirstFile.csv', 'SecondFile.csv' |
Export-Csv -Path .\Export.csv -NoTypeInformation
foreach ($file in $dir1) {
# Import the CSV
$dir1CSV = Import-Csv -Path $file.FullName
# for each file in directory that will append to source
foreach ($csv in $dir2) {
# Import the file that will be appended
$dir2Csv = Import-Csv -Path $csv.FullName
# for each property in that file
foreach ($prop in $dir2Csv.PSObject.Properties) {
# Append the properties to the source data
$dir1CSV | Add-Member -MemberType NoteProperty -Name $prop.Name -Value $prop.Value -Force
}
}
$dir1CSV | Format-Table -AutoSize
#$dir1CSV | Export-Csv C:\TEmp\NewFIleFormat.csv -NoTypeInformation
}