Friday, 30 October 2015

Import Items from CSV and Export to Sharepoint List.

Add-PSSnapin Microsoft.SharePoint.PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$contents = Import-CSV "D:\Test\List.csv" -header("Title", "SiteURL", "CreatedBy"-delimiter ';'

# Web URL
$webURL = “http://server:port/Site”
$web = Get-SPWeb -Identity $webURL
$listName = "List Name"
$list= $web.Lists["$listName"] 

# Iterate for each list column
$count = 0
foreach ($row in $contents )
{  
    $count++
    $item = $list.Items.Add();
    $item["Title"] = $row.Title
    $item["URL"] = $row.SiteURL
    $item["Created By"] = $row.CreatedBy
    $item.Update()
}
Write-Host -ForegroundColor green "List Updated Successfully"
$web.Dispose()

No comments:

Post a Comment