Friday, June 16, 2017

PowerShell to Add Data Row-wise to CSV File

Execute following script to insert data in new or existing CSV file.

$FilePath = "D:\Data\FileName,csv"
#Add Title Row
$Row = "Full Name,Age,Gender"
Add-Content ($Row) -Path $FilePath

#Add Data Row
$Name = "Prashant"
$Age = "29"
$Gender = "Male"
$Row = $Name + "," + $Age + "," + $Gender
Add-Content ($Row) -Path $FilePath

No comments: