0

I have a document library with 4,500 documents, half of the documents have unique permissions and don't inherit permission from the document library. What I am trying to achieve is to delete the unique permissions from those documents. Is there any way I can do this with PowerShell?

Kind Regards

1

SharePoint Online: Delete Unique Permissions from a List/Library using PnP PowerShell

#Set Variables
$SiteURL = "https://tenant.sharepoint.com/sites/sitename"
$ListName = "Documents"
  
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
 
#Get all list items in batches
$ListItems = Get-PnPListItem -List $ListName -PageSize 5000
 
#Iterate through each list item
ForEach($ListItem in $ListItems)
{
    #Check if the Item has unique permissions
    $HasUniquePermissions = Get-PnPProperty -ClientObject $ListItem -Property "HasUniqueRoleAssignments"
    If($HasUniquePermissions)
    {       
        $Msg = "Deleting Unique Permissions on {0} '{1}' at {2} " -f $ListItem.FileSystemObjectType,$ListItem.FieldValues["FileLeafRef"],$ListItem.FieldValues["FileRef"]
        Write-host $Msg
        #Delete unique permissions on the list item
        Set-PnPListItemPermission -List $ListName -Identity $ListItem.ID -InheritPermissions
    }
}

SharePoint Server: Remove unique permissions on List Items

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
 
#Variables for Web URL, List Name
$WebURL ="http://spserver/sites/sitename"
$ListName ="Documents"
 
#Get the list items with Unique permissions
$ListItems = (Get-SPweb $WebURL).lists.TryGetList($ListName).Items | Where {$_.HasUniqueRoleAssignments}
 
# If List Exists with Unique permission
Foreach($ListItem in $ListItems)
 {
      #Reset broken list item inheritance
      $ListItem.ResetRoleInheritance()
      Write-host "Broken Inheritance Reset on List Item:" $ListItem.URL
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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