[Powershell] – Import to Sharepoint List from CSV
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
# define web application where list is located
$web = Get-SPWeb http://contoso/
$list = $web.lists["List Name"]
$cnt = 0
# define csv document path
foreach($i in Import-CSV 'E:\Scripts\Excel\ImportFromCSV.csv')
{
$new = $list.Items.Add()
$new[“Title”] = $i.'Title'
$new.Update()
$cnt++
}
"Added " + $cnt.ToString() + " records."
"Data successfully imported. Press any key to continue…"
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
Please take note that this code must be run on the same server where the web application is with authenticated privilege.
Recent Comments