Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Date column to an existing csv file
$today = [System.DateTime]::Today.ToString("yyyyMMdd")
Import-Csv -Header Column1,Column2 -Delim ',' 'C:\sample.csv' |
ForEach {
New-Object psobject -Property @{Date=$today;Col1=$_.Column1; Col2=$_.Column2}
} | Select-Object Date,Col1,Col2 | Export-Csv -NoTypeInformation 'C:\sample.csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment