SharePoint Online: Bulk Update All Items in Large List using PowerShell
Requirement: Bulk Update SharePoint Online List Items using PowerShell
How to Update Large Number of List Items in Bulk using PowerShell?
While lists < 5000 items can be updated using the approach in my another 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".
How to Update Large Number of List Items in Bulk using PowerShell?
While lists < 5000 items can be updated using the approach in my another 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" #Parameters $SiteURL = "https://crescenttech.sharepoint.com" $ListName = "Documents" $UserName = "Salaudeen@CrescentTech.com" $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) $Ctx.Load($List) $Ctx.ExecuteQuery() #Define CAML Query to get Files from the list in batches $Query = New-Object Microsoft.SharePoint.Client.CamlQuery $Query.ViewXml = "@ <View Scope='RecursiveAll'> <Query> <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy> </Query> <RowLimit>$BatchSize</RowLimit> </View>" #Get List Items in Batches Do { #Get List Items $ListItems = $List.GetItems($Query) $Ctx.Load($ListItems) $Ctx.ExecuteQuery() $ListItems.Count #Update Postion of the ListItemCollectionPosition $Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition $Query.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"] $Item.Update() } $Ctx.ExecuteQuery() }While ($Query.ListItemCollectionPosition -ne $null)
SharePoint Online: Bulk Update All Items in Large List using PowerShell
Reviewed by Salaudeen Rajack
on
June 14, 2018
Rating:
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"
ReplyDeleteScript has been updated, Try now!
DeleteThis now works. Thank you so much!
DeleteI'm not very strong in the Power Shell world yet, I truly appreciate your help.