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
Olaf
  • 4,690
  • 2
  • 15
  • 23
  • 2
    You have a line break after the parameter name `-Property`. That's not allowed. Remove it and it wioll work. And ... there are curly braces missing around your expressions in your calculated properties. – Olaf Aug 31 '21 at 19:23
  • Please consider marking the answer that solved your issue as the solution. – Dennis Sep 16 '21 at 18:47

1 Answers1

1

If you really like to break the line of the select-command anyway, tell PowerShell to continue on the next by using a backtick (`)...

And I'm sure you like to keep all the current data that you are piping as well while removing the old column names :)

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
Dennis
  • 871
  • 9
  • 29
  • 1
    Even if that works it is considered a very bad style. And you have to be careful with the back tick. It is **not** a line continuation charachter. It is an escape charachter. If you accidentally put a space after it it will break your code. ;-) And regardless of that the question was about not to get all columns. ;-) – Olaf Aug 31 '21 at 20:29
  • 1
    "rename the column names" – Dennis Aug 31 '21 at 20:34