1

I can manually set an index on a column in a large SharePoint list (10000+ items) but I'm not able to do it programmatically.

With (PnP) PowerShell I've tried:

# get context
$Context = Get-PnPContext     
# set 
$fieldtocheck.indexed = $true
$fieldtocheck.update()
$Context.ExecuteQuery()

The last part ($Context.ExecuteQuery()) fails on a large list.

I've also tried using graph:

$uri = "https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/contosesite:/lists/listguid/columns/columntobeindexed"

$json = @'
{
"indexed":"true"
}
'@ 
Invoke-MgGraphRequest -uri $uri -body $json -Method PATCH -ContentType "application/json"

which also fails with: The request is unprocessable because it uses too many resources.

Is there a way without doing it manually by setting an index on a colummn in a large list? Thanks in advance.

2 Answers 2

1

There is a trick!

  1. Delete a few items until you are below (maybe) 5000 items.
  2. After that, try to index the field.
  3. Once it works, go to the site recycle bin and restore the deleted items
0

You could use following PowerShell to create Index column.

#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ListName = "Projects"
$ColumnName = "ProjectName" #Internal Name
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
 
#Get the Context
$Context = Get-PnPContext
 
#Get the Field from List
$Field = Get-PnPField -List $ListName -Identity $ColumnName
 
#Set the Indexed Property of the Field
$Field.Indexed = $True
$Field.Update()
$Context.ExecuteQuery()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.