0

I'm trying to add a new header column to a .csv file with using powershell. When this is done the next step is to fill all data columns with the same entry it should look like this:

Before:

Name;Kind;Type1;Type2;Type3;
Function1;Method;something1;something1;something1;
Function2;Method;something1;something1;something1;

After:

Name;Kind;Type1;Type2;Type3;Version
Function1;Method;something1;something1;something1;1
Function2;Method;something1;something1;something1;1

So because of the file has ~35 columns and ~30000 rows i need to loop through But i dont know how to get to the end of a line.

1 Answer 1

2

You can do this:

$inFile = "C:\path\to\your\file.csv"
$outFile = "C:\path\to\your\modifications.csv"
$v = Import-Csv -Delimiter ';' $inFile
$v | % { $_ | Add-Member -NotePropertyName "Version" -NotePropertyValue 1 }
$v | ConvertTo-Csv -Delimiter ';' -NoTypeInformation | Out-File $outFile

Import the csv file to a powershell object, then iterate over all the lines and use the Add-Member cmdlet to add an extra property.

Then convert the object back to csv format and save to a new file. You can of course overwrite the original file with this, but be careful the information is correct before you do it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.