Sunday, February 23, 2014

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.

powershell import xml to sharepoint list

Here is a sample XML file, generated by the tool:
<?xml version="1.0"?>
 <project id="PMO.1120">
  <description>GIS upgrade 2013 </description>
 <project id="PMO.1121">
  <description>HRIT Asset Life Cycle Automation</description>

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  = ""
$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"] = $
        $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

        Write-Host "Project $($ 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

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:


  1. Hi
    Is it possible for SharePoint Online? Let me know your comments on importing data from XML to SharePoint Online.


Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...