How to Insert a Sequential Unique Integer ID Value in a CSV File Using PowerShell

Posted By Posted by: EPM Partners on May 30, 2013

#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


# 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

Blog Posted In Blog Posted In: How to
Blog Posted In 

Leave a Reply

Your email address will not be published.