SharePoint Online: Import XML to List using PowerShell

Requirement:  Import XML to SharePoint Online List.

PowerShell to Import XML to SharePoint Online List

Importing data from an XML file to a SharePoint Online list using PowerShell can be a useful way to migrate data from another system or to update existing list data. This article describes how to import an XML file into a SharePoint Online list using PowerShell.

Here is the PowerShell to import XML to the SharePoint Online list:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set parameter values
$XMLFile ="C:\Temp\ProjectData.xml"

    #Get Credentials to connect
    $Cred= Get-Credential
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Get the web & List objects
    $Web = $Ctx.Web
    $List = $Web.Lists.GetByTitle($ListName)

    #import xml file
    [xml]$ProjectXmlFile = Get-Content $XMLFile
    #Iterate through each "Project" node of the XML file
    Foreach ($XMLProject in $ProjectXmlFile.projects.project)
        #Add New List Item
        $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
        $NewProject = $List.AddItem($ListItemInfo)

        #Map XML fields to SharePoint Online List Fields - Internal Name
        $NewProject["ProjectID"] = $
        $NewProject["Title"] = $XMLProject.ProjectName
        $NewProject["ProjectDescription"] = $XMLProject.description
        $NewProject["ProjectManager"] = $web.EnsureUser($XMLProject.manager)
        $NewProject["Domain"] = $XMLProject.domain
        $NewProject["Budget"] = $XMLProject.budget
        $NewProject["StartDate"] = $XMLProject.startdate
        Write-Host "Project $($ has been Imported to the Projects List!"
Catch {
        write-host -f Red "Error Importing XML Data into List!" $_.Exception.Message

My XML Structure:

<?xml version="1.0" encoding="UTF-8"?>
    <project id="PMO-1250">
        <projectname>SharePoint 2016 Upgrade</projectname>
        <description>Migration Project to Move from SharePoint 2010 to SharePoint 2016</description>
        <domain>IT Applications</domain>
    <project id="PMO-1121">
        <projectname>Azure Data center Migration</projectname>
        <description>Azure Data center Migration Project</description>
        <domain>IT Infrastructure</domain>

Here is the List structure I created before running the script:

sharepoint online import xml to list using powershell

Here is another post was written for SharePoint On-premises: PowerShell to Import XML to SharePoint List

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *