SharePoint Online: Bulk Update All Items in Large List using PowerShell

Requirement: Bulk Update SharePoint Online List Items using PowerShell.
PowerShell to Bulk Update All Items in Large List in SharePoint Online

How to Update a Large Number of List Items in Bulk using PowerShell?
While lists < 5000 items can be updated using the approach in my other post, Update SharePoint Online List using PowerShell, How about updating large lists with more than 5000 list items?

Well, large lists must be updated in batches. Here is my PowerShell script to update large lists in bulk: This PowerShell script updates the "Title" field value from "File Name".
#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"
$SiteURL = ""
$ListName = "Documents"
$UserName = "[email protected]"
$Password = "Password123456"
$SecurePassword= $Password | ConvertTo-SecureString -AsPlainText -Force
$BatchSize =100
#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)

#Define CAML Query to get Files from the list in batches
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "@
    <View Scope='RecursiveAll'> 
             <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>

#Get List Items in Batches
    #Get List Items 
    $ListItems = $List.GetItems($Query)

    #Update Postion of the ListItemCollectionPosition
    $Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition

    If ($ListItems.Count -eq 0) { Break }
    #Update List Item
    ForEach($Item in $ListItems)
        #Update List Item Title as File Name
        $Item["Title"]= $Item["FileLeafRef"]
}While ($Query.ListItemCollectionPosition -ne $null)

PnP PowerShell to Update All Items in a SharePoint Online List Updating multiple list items using PnP PowerShell is relatively simpler than the above CSOM script (That's the Power of PnP!).
$SiteURL = ""
$ListName = "Projects"

#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -UseWebLogin

#Get all Items from the list
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000

#Update all list Items
ForEach($Item in $ListItems)
    #Update List Item Title as its ID value
    Set-PnPListItem -List $ListName -Identity $Item.Id -Values @{"Title"= $Item.Id} | Out-Null
    Write-host "Updated Item:"$Item.ID    

If you want to bulk update multiple items from a CSV file, use: Update SharePoint Online List from a CSV using PowerShell


  1. I haven't been able to get this to work on lists over 5000. On lists under 5000 items, I see that it processes items in batches of 100 and have verified that the items have been updated. On a list over 5000, I get the dreaded "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator"

    1. Script has been updated, Try now!

    2. This now works. Thank you so much!

      I'm not very strong in the Power Shell world yet, I truly appreciate your help.


Please Login and comment to get your questions answered!

Powered by Blogger.