0

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

  • See [Is there a PowerShell equivalent of `paste` (i.e., horizontal file concatenation)? (duplicate)](https://stackoverflow.com/a/68070763/1701026) – iRon Sep 21 '22 at 16:01

1 Answers1

1

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
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206