我试图弄清楚我需要做些什么才能将字段放入csv文件但不是最后。我有field1,field2,field3,field4。我需要在这些字段的中间放置一个字段..field1,field2,NEWFIELD,field3,field4。我有这个代码,但它把它放在最后。
$objTable | Export-CSV -NoTypeInformation $AttachmentPath
# get the file content
$csv = get-content $AttachmentPath
# add two columns to the header row
$csv[0] += ",AD_Site_Name"
# write the changes back
$csv | out-file c:\scripts\test.csv
#import new csv with new columns
import-csv c:\scripts\test.csv
答案 0 :(得分:1)
试试这个:
$objTable | Export-CSV -NoTypeInformation $AttachmentPath
Import-CSV $AttachmentPath |
Select Field1,Field2,NEWFIELD,Field3,Field4 |
Export-CSV c:\scripts\test.csv