0

We need to create around 9000 SharePoint groups in our site collection with specific names and custom permissions for each, currently we have a console app which will automate the group creation with custom permissions through CSOM, It is working well till the total group count reaches 5000, after that we are getting threshold issue like below:

Microsoft.SharePoint.SPQueryThrottledException "The attempted operation is prohibited because it exceeds the list view threshold."

So we tried to create groups using PnP PowerShell also like below:

$Group = New-PnPGroup -Title $GroupName -ErrorAction Stop

Set-PnPGroupPermissions -Identity $GroupName -AddRole $Permission -Web $Web

There also we facing the same issue and getting error like below:

Set-PnPGroupPermissions : The attempted operation is prohibited because it exceeds the list view threshold.

According to SharePoint documentation we can have up to 10000 groups per site collection please refer screenshot below:

enter image description here

Kindly help us with workaround for this issue.

1 Answer 1

0

This is the expected behavior of SharePoint Online sites. You can try batching process for the same to create groups in small bunches.

We used below pnp-powershell code chunk to create groups in past(but not as 9000) that I am sharing with you. You can adjust your batch size and delay between each batch run as per your tenant's performance.

# Define the batch size
$batchSize = 500

# Function to create groups in batches
function Create-GroupsInBatches {
    param (
        [string]$GroupNamePrefix,
        [int]$TotalGroups,
        [string]$Permission,
        [Microsoft.SharePoint.Client.Web]$Web
    )

    $batchCount = [math]::Ceiling($TotalGroups / $batchSize)

    for ($batch = 0; $batch -lt $batchCount; $batch++) {
        $start = $batch * $batchSize
        $end = [math]::Min($start + $batchSize, $TotalGroups)

        for ($i = $start; $i -lt $end; $i++) {
            $GroupName = "$GroupNamePrefix-$i"
            try {
                $Group = New-PnPGroup -Title $GroupName -ErrorAction Stop
                Set-PnPGroupPermissions -Identity $GroupName -AddRole $Permission -Web $Web
                Write-Host "Created group: $GroupName"
            } catch {
                Write-Host "Error creating group: $GroupName - $_"
            }
        }

        # Pause to avoid hitting the threshold
        Start-Sleep -Seconds 10
    }
}

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Credentials (Get-Credential)

# Call the function to create groups
Create-GroupsInBatches -GroupNamePrefix "Group" -TotalGroups 9000 -Permission "Contribute" -Web (Get-PnPWeb)
3
  • 1
    Thank you Dikesh will try the script and let you know. Commented Oct 24 at 16:54
  • @anantharengan - Is it helpful to you? If Yes, please accept and upvote this answer so it will help others. Commented Nov 5 at 11:20
  • Will let you know soon Commented Nov 10 at 19:31

Your Answer

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

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