PowerShell TIP – ADD extra column to existing CSV

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

https://techwizard.cloud

https://syscloudpro.com/

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s