0

Is there a simple way (i.e. easy to explain and to do by users) to remove unique permissions when moving or copying a document from one library to another? All documents moved to the target library should inherit permissions and not be shared with individuals any longer.

I could create workflows in Power Automate or consider making a custom command set SPFX solution, but I have several libraries with more to come so looking for the easiest, scalable solution, so am looking for OOTB options

1 Answer 1

0

Whether you want to remove unique permissions for one document in a library or remove unique permissions for all documents in a library?

I suggest you use PowerShell to remove unique permissions.

For a document in the library:

#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-ListItemUniquePermissions
{
param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ListName,
        [Parameter(Mandatory=$true)] [string] $ItemID       
    )
 
    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
 
        #Remove unique permissions and reset inheritance
        $List=$Ctx.Web.Lists.GetByTitle($ListName)
        $ListItem=$List.GetItemByID($ItemID)
        $ListItem.ResetRoleInheritance()
        $Ctx.ExecuteQuery()
 
        Write-Host "Unique Permissions are removed and inherited from the Parent!" -ForegroundColor Green
    }
 
    Catch {
        write-host -f Red "Error Deleting Unique Permissions!" $_.Exception.Message
    } 
}
 
#Parameters
$SiteURL="https://tenant.sharepoint.com"
$ListName="list name"
$ItemID="Item ID"
 
#Call the function to remove unique permissions from a list
Remove-ListItemUniquePermissions -SiteURL $SiteURL -ListName $ListName -ItemID $ItemID 

For all documents in the library:

#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
{
param
    (
        [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
        $List=$Ctx.Web.Lists.GetByTitle($ListName)
        $List.ResetRoleInheritance()
        $List.Update()
        $Ctx.ExecuteQuery()
 
        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
$SiteURL="https://tenant.sharepoint.com"
$ListName="list name"
 
#Call the function to remove unique permissions from a list
Remove-ListUniquePermissions -SiteURL $SiteURL -ListName $ListName
2
  • Thank you @Emily Du! But I think we would have to keep on running this script when new documents are moved with custom permissions? Or is this script simply disabling the possibily to create custom permissions? (that would be ideal)
    – JJD
    Commented Jul 8, 2021 at 9:33
  • You could run SharePoint Online PowerShell by using Power Automate. In the flow, set trigger as "When an item is created or modified". You could refer this article in the Microsoft Q&A. docs.microsoft.com/en-us/answers/questions/466764/… Commented Jul 9, 2021 at 10:07

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.