Import XML File Data into SharePoint List using PowerShell
Requirement: PowerShell to Import XML to SharePoint List
We've an utility from third-party system that generates project data in XML format. We had to import those data to a list in the PMO site. In other words: We've to import from XML file to SharePoint list.
Here is a sample XML file, generated by the tool:
Using PowerShell, lets import XML data into SharePoint list.
PowerShell script to read from XML and import to SharePoint list:
Here is how to import XML into sharepoint list
If you are looking for a way to export SharePoint list items to XML, Refer: Export SharePoint List to XML using PowerShell
We've an utility from third-party system that generates project data in XML format. We had to import those data to a list in the PMO site. In other words: We've to import from XML file to SharePoint list.
Here is a sample XML file, generated by the tool:
<?xml version="1.0"?> <projects> <project id="PMO.1120"> <description>GIS upgrade 2013 </description> <manager>global\E372440</manager> <cost>$35000</cost> <startdate>1/1/2014</startdate> </project> <project id="PMO.1121"> <description>HRIT Asset Life Cycle Automation</description> <manager>AMER\E132321</manager> <cost>$63000</cost> <startdate>1/1/2014</startdate> </project> </projects>
Using PowerShell, lets import XML data into SharePoint list.
PowerShell script to read from XML and import to SharePoint list:
Here is how to import XML into sharepoint list
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set these two variables accordingly $WebURL = "http://project.crescent.com/" $ListName = "External Projects" $XMLFilePath = "D:\data\ExternalProjects.xml" #Get the Web $web = Get-SPWeb $WebURL #Get the List $ProjectList = $web.Lists[$ListName] #import xml file [xml]$ProjectXmlFile = Get-Content $XMLFilePath foreach ($XMLProject in $ProjectXmlFile.projects.project) { $NewProject = $ProjectList.Items.Add() $NewProject["Project ID"] = $XMLProject.id $NewProject["Description"] = $XMLProject.description #Set the People Picker Field $NewProject["Project Manager"] = $web.EnsureUser($XMLProject.manager) $NewProject["Cost"] = $XMLProject.cost $NewProject["Start Date"] = $XMLProject.startdate $NewProject.Update() Write-Host "Project $($XMLProject.id) has been Added to External Projects list!" }That's all! we are done importing XML data to SharePoint list with PowerShell!!
If you are looking for a way to export SharePoint list items to XML, Refer: Export SharePoint List to XML using PowerShell
Import XML File Data into SharePoint List using PowerShell
Reviewed by Salaudeen Rajack
on
February 23, 2014
Rating:

Hi
ReplyDeleteIs it possible for SharePoint Online? Let me know your comments on importing data from XML to SharePoint Online.
Thanks
Yes! You can use PowerShell-CSOM. Refer: SharePoint Online: Import CSV File into SharePoint List using PowerShell-CSOM
Delete