Migrate data from CSV to SharePoint List – PowerShell


Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

$FilePathCSV = import-csv D:\Book1.csv

$webURL = "http://url"
$listName = "CSVInput"
$web = Get-SPWeb $webURL
$list = $web.Lists[$listName]

foreach($CurrentRwo in $FilePathCSV)
{
$field1 = $CurrentRwo.Name
$field2 = $CurrentRwo.Age

$newItem = $list.Items.Add()
$newItem["Title"] = $field1
$newItem["Age"] = $field2

$filebytes = [System.IO.File]::ReadAllBytes("D:\Book1.csv")
$newItem.Attachments.Add("DummyFile Title",$filebytes)
$newItem.Update()
}