I have a problem with my Sharepoint. I migrated data from NAS to SPO using a migrate tool. This solution adds unique permission to the library and sublibraries. I have more than 250k objects so I can't use web site to delete this, I tried to use this method Remove unique permissions on all locations on site SharePoint 2013

I Changed the start function from Get-SPWeb to Get-SPOService.

this does not work. Could you help me, how can I delete unique permission in one library on one site in Sharepoint online when is it more than 5000 objects?

  • Hello Jarkacz, Could you please provide a resource for the migration tool that you used from NAS to SPO? I look forward to your response.
    – SmithBZ
    Dec 9, 2021 at 20:26

2 Answers 2


You could try the below powershell script:

$ListName = "Documents"
Connect-PnPOnline -Url https://yoursite
#Get all list items in batches
$ListItems = Get-PnPListItem -List $ListName -PageSize 500
#Iterate through each list item
ForEach($ListItem in $ListItems)
    #Check if the Item has unique permissions
    $HasUniquePermissions = Get-PnPProperty -ClientObject $ListItem -Property "HasUniqueRoleAssignments"
      Set-PnPListItemPermission -List $ListName -Identity $ListItem.ID -InheritPermissions




  • i have message: Get-PnPContext : The term 'Get-PnPContext' is not recognized as the name of a cmdlet, function, script file, or operabl e program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. i changed connect-pnponline to connect sposervice because i have SPonline
    – jarkacz124
    May 6, 2020 at 9:38
  • You need to use Install-Module SharePointPnPPowerShellOnline to intall pnp powershell:docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/… May 6, 2020 at 9:46
  • thanks a lot! i have ~275k items but i see this is work.
    – jarkacz124
    May 6, 2020 at 11:22

You could try the below PowerShell script:

#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"

#Function to remove unique permissions and inherit from the parent
Function Remove-ListUniquePermissions
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials

        #sharepoint online powershell inherit permissions

        Write-Host "Unique Permissions are removed and inherited from the Parent!" -ForegroundColor Green

    Catch {
        write-host -f Red "Error Deleting Unique Permissions!" $_.Exception.Message
#sharepoint online powershell reset permissions

#Call the function to remove unique permissions from a list
Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName


For more than 5000 items condition, you need to load the items with a row limit 5000 - if the result gives more than 5k then need to call the above function Remove-ListUniquePermission

Example of how to call the above function Remove-ListUniquePermission

$list = $ctx.Web.Lists.GetByTitle($DocLibName)
## View XML
$camlQuery= @"
<View Scope="RecursiveAll">
        <OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy>
    <RowLimit Paged="TRUE">5000</RowLimit>

$currentCollection = $list.GetItems($camlQuery)

if ($currentCollection -eq 5000)
   Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName



Delete Unique Permissions on a List or Library in SharePoint Online using PowerShell:

Get All Items in 5000+ large list with CSOM in PowerShell

  • "$ListName="Projects" what if i don't have any list? i want use script only to library
    – jarkacz124
    Apr 28, 2020 at 9:57
  • You can pass as $ListName="YourLibraryName"
    – SP 2022
    Apr 28, 2020 at 10:05
  • thx, but i checked, and this is not delete unique permission in subfolders but only only in the library I pointed out
    – jarkacz124
    Apr 28, 2020 at 11:06
  • sorry for stupuid question but i must change $DocLibName and $list? i try to reset permission for #sharepoint online powershell reset permissions $SiteURL="silfraconsulting.sharepoint.com/sites/Public" $ListName="Dokumenty"
    – jarkacz124
    May 6, 2020 at 9:34

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.