How can I write PowerShell to Break Permission Inheritance for all document libraries in a Site

adil 1,411 Reputation points
2020-11-05T10:29:18.753+00:00

How can I write PowerShell to Break Permission Inheritance for all document libraries in a Site , because of there are many document libraries in in sites instead of going each document library

Microsoft 365 and Office | SharePoint Server | For business

2 answers

Sort by: Newest
  1. Jerry Xu-MSFT 7,961 Reputation points
    2020-11-06T02:18:02.66+00:00

    Hi, @adil ,

    I assume your are using SharePoint On-Premise. Please have a try with the script below

    #Configuration Parameters  
    $WebURL="siteURL"  
      
       
    #Get the List  
    $Web = Get-SPWeb $WebURL  
    $Lists = $web.Lists  
    Foreach($List in $Lists)  
    {  
     #Return only document libraries  
     if ($List.baseTemplate -eq "DocumentLibrary")  
     {  
     #Check if the library has unique permission  
     if ($List.HasUniqueRoleAssignments -eq $False)  
     {  
     $List.BreakRoleInheritance($True)  
     Write-host $List.Title "Stopped Inheriting Permissions from the parent." -f Green  
     }  
     else  
     {  
     write-host $List.Title "List is already using Unique Permissions!" -f Red  
     }  
     }  
      
    }  
    

    If the answer is helpful, please click Accept Answer and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.