How to Insert a sequential unique integer ID value in a CSV file using PowerShell

#Import the CSV file data into Variable and add the blank new ID column

$CSV = import-csv “D:\Temp File\Temp.csv” | select Employee_ID, @{Name=”Id”;Expression={$_.””}}

# so we start from ID = 1 in the CSV file

$x=1;

# this will loop each row in CSV and insert the incremental unique ID value

FOREACH($ReadData in $CSV) {$ReadData.Id=$x;$x++}

#Export the data from the Variable to new file

$CSV| export-csv “D:\Temp File\Temp1.csv” -NoTypeInformation

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: