Forum Discussion

Ivan54's avatar
Ivan54
Bronze Contributor
Jan 25, 2018

Need PowerShell Script to remove broken inheritance

Hi,

 

I'm having an issue with a specific document library in SharePoint Online that is being synced to a department.

This document library resides in a Classic SharePoint Site, turned into modern view manually.

For some reason every time a user creates a document or folder in that document library (through the Windows 10 v1709 Windows Explorer - OneDrive Sync) the permission inheritance on that file/folder is broken and only the CREATOR has permissions. Therefore nobody else sees those files and folders.

 

Now I need a PowerShell script that will remove all the broken inheritances from a specific document library in SharePoint Online. 

I've searched online, but only found scripts that seem to work with old SP onPrem solutions.

4 Replies

  • Rob Ellis's avatar
    Rob Ellis
    Bronze Contributor
    I've used this one successfully with SPO in the past:

    https://gallery.technet.microsoft.com/office/Delete-unique-permissions-8fd47022
    • Ivan54's avatar
      Ivan54
      Bronze Contributor
      Thanks Rob,
      I think this should work, but unfortunately PowerShell ISE crashes after a few minutes.
      The DocLib has over 6000 items, maybe that is the reason.


      I'd like to limit the script to items with broken inheritances instead of the full DocLib to maybe work around the crash.
      Can you help me incorporate this information into the script?

      Arleta Wanat
      It resets the permissions for every item. If you want to check only the ones with unique permissions, add an if condition to check for HasUniqueRoleAssignments property.

      A very good explanation on how to load the values for the property is available here:
      https://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell

Resources