Sharing PowerShell TIP on how to ADD an extra column to existing CSV file.
I have got this requirement many a times from Tableau or PowerBI team to add an extra column Date in existing CSV file.
Step 1 à
$data = Import-CSV c:\csvfile.csv
Import CSV file into a variable $data
Step 2 à
$getdate = get-date -format D
Step 3 à
$data | Select-Object *, @{n=”Date”;e={$getdate}} | Export-CSV c:\newcsvfile.csv -NoTypeInformation
ADD the computed date value in step 2 in select expression and export as new csv file.
Here is the result:
Now use this TIP to automate it in a script and make your PowerBI and Tableau or BI team happy :).
Thanks for reading….
Tech Wizard