Reputation: 1
I'm trying to read a csv file in powershell and for each item from the first column I am running a powershell command and I want the output to be added to the next column in the corresponding row. The problem is that I don't know how to add the output from the command to the CSV in the corresponding row. Ex:
To
A1,B1
A2,B2
A3,B3
add C1,C2,C3
as
A1,B1,C1
A2,B2,C2
A3,B3,C3
Upvotes: 0
Views: 138
Reputation: 174700
Use Select-Object *
to create new objects that are copies of the input, then add an additional property to each object by using a calculated property:
Import-Csv original.csv |Select-Object *,@{Name='NewColumnName';Expression={ Get-NewColumnValue }} |Export-Csv output.csv -NoTypeInformation
Upvotes: 1