magritton
11/16/2015 - 9:36 PM

Powershell script to extract data out of a CSV and place it into a SharePoint list.

Powershell script to extract data out of a CSV and place it into a SharePoint list.

Add-PsSnapin Microsoft.SharePoint.PowerShell
# CSV path/File name
$contents = Import-Csv "c:\temp\MarketingSupply.csv"

# Web URL
$web = Get-SPWeb -Identity "http://scushp01/marketing" 

# SPList name
$list = $web.Lists["MarketingSupplyItems"] 


# Iterate for each list column
$i = 1
foreach ($row in $contents) {
    $i
    $i++
    $item = $list.Items.Add();
    $item["SupplyCategory"] = $row.SupplyCategory;
    $item["SupplyItemName"] = $row.SupplyItemName;
    $item["SupplyItemPicture"] = $row.SupplyItemPicture;
    $item.Update();
}
Add-PsSnapin Microsoft.SharePoint.PowerShell
# CSV path/File name
$contents = Import-Csv "c:\temp\Branch.csv"

# Web URL
$web = Get-SPWeb -Identity "http://scushp01" 

# SPList name
$list = $web.Lists["Branches"] 


# Iterate for each list column
$i = 1
foreach ($row in $contents) {
    $i
    $i++
    $item = $list.Items.Add();
    $item["Title"] = $row.BranchName;
    $item["BranchNumber"] = $row.BranchNumber;
    $item["Address"] = $row.Address;
    $item["City"] = $row.City;
    $item["State"] = $row.State;
    $item["Country"] = $row.Country;
    $item["ZipCode"] = $row.ZipCode;
    $item.Update();
}
# CSV path/File name
$contents = Import-Csv "c:\temp\jduty.csv"

# Web URL
$web = Get-SPWeb -Identity "http://scushp01/sites/Testing/" 

# SPList name
$list = $web.Lists["JobDuties"] 


# Iterate for each list column
$i = 1
foreach ($row in $contents) {
    $i
    $i++
    $item = $list.Items.Add();
    $item["Dept"] = $row.Dept;
    $item["DeptExt"] = $row.DeptExt;
    $item["Employee"] = $row.Employee;
    $item["EmployeeExt"] = $row.EmployeeExt;
    $item["Duty"] = $row.Duty;
    $item.Update();
}