0

I am trying to simply rename the column names from an existing CSV and then export the new one.

I do not want all columns. Only specific. All examples I have seen show how to do all, instead of specific columns.

But I am stuck on this error:

Select-Object : Missing an argument for parameter 'Property'. Specify a parameter of type 'System.Object[]' and try again.

Import-Csv "ORIGINALFILEPATHHERE" | 
Select-Object -Property 
@{name="Dept";expression=$_.'Account'},
@{name="Office";expression=$_.'Location'}| 
Export-Csv -Path "EXPORTPATHHERE"  -NoTypeInformation -UseCulture -Force
4

1 回答 1

1

如果您真的想打破 - 命令的行,请select使用反引号 ( ) 告诉 PowerShell 继续下一个`...

而且我确定您喜欢在删除旧列名的同时保留所有当前正在传输的数据:)

Import-Csv "ORIGINALFILEPATHHERE" | 
Select-Object -Property *, `
@{name='Dept';expression={$_.Account}},
@{name='Office';expression={$_.Location}} | 
Select-Object -Property * -ExcludeProperty Account,Location|
Export-Csv -Path "EXPORTPATHHERE"  -NoTypeInformation -UseCulture -Force
于 2021-08-31T20:13:21.803 回答