Add Column to CSV Windows PowerShell

Here’s one way to do that using Calculated Properties:

Import-Csv file.csv | 
Select-Object *,@{Name="column3";Expression={'setvalue'}} | 
Export-Csv file.csv -NoTypeInformation

You can find more on calculated properties here: http://technet.microsoft.com/en-us/library/ff730948.aspx.

In a nutshell, you import the file, pipe the content to the Select-Object cmdlet, select all exiting properties (e.g ‘*’) then add a new one.

Leave a Comment