Sunday, February 23, 2014

Import XML File Data into SharePoint List using PowerShell

Requirement: 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"?>
 <project id="PMO.1120">
  <description>GIS upgrade 2013 </description>
 <project id="PMO.1121">
  <description>HRIT Asset Life Cycle Automation</description>

Solution: Using PowerShell, lets import XML data into SharePoint list.

PowerShell script to read from XML and import to 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:

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:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...