I need to import this csv, then export while changing header names and omitting columns. The first csv column headers include spaces. The script I am using is not working. Thank you for any help.

import-csv c:\info1.csv | select -Property @{name="LastName";expression={$("$_.Last Name")}},@{name="FirstName";expression={$("$_.First Name")}},@{name="Address";expression={$("$_.Main Address")}},@{name="LastName";expression={$("$_.Last Name")}},@{name="Phone";expression={$("$_.Main Phone")}} | Export-Csv c:\info.csv -NoTypeInformation

Import file - info1.csv

Last Name, First Name, Main Address, Main ID, Main Phone, Main Title, Main Department

Glover, Steve, 365 Work, 2018, 555-555-5555, Powershell Noob, Technology


Export file - info.csv

LastName, FirstName, Address, Phone

Glover, Steve, 365 Work, 555-555-5555

3 Spice ups

WHat specifically isn’t working? When renaming headers it should be label, not name.

select -Property @{label="LastName";expression={$($_."Last Name")}},@{label="FirstName";expression={$($_."First Name")}},@{label="Address";expression={$($_."Main Address")}},@{label="LastName";expression={$($_."Last Name")}},@{label="Phone";expression={$($_."Main Phone")}}
1 Spice up

Thank you for the tip on label vs name. I made that change but I get the same result. Labels are getting renamed, however, data from all columns are in each column.

LastName, FirstName, Address, Phone

@{Last Name=Glover;First Name=Steve;365 Work;Main Address=365 work;Main Phone=555-555-5555;@{Last Name=Glover;First Name=Steve;365 Work;Main Address=365 work;Main Phone=555-555-5555;@{Last Name=Glover;First Name=Steve;365 Work;Main Address=365 work;Main Phone=555-555-5555;@{Last Name=Glover;First Name=Steve;365 Work;Main Address=365 work;Main Phone=555-555-5555

This is in each cell.

Wow, I have really messed up this script I guess. Once I think I am learning Powershell, nope, I was wrong.

Paste my sample into your code after the first pipe. You have your ""s in the wrong place.

1 Spice up

Perfect. Thank you for the help. You are a scholar and a gentleman sir.