Latest Posts

Set-PnPList: Break Role Inheritance On List in SharePoint using PowerShell

The example in this topic show how to use PowerShell to Break Role Inheritance On List in SharePoint
  • Using PnP (Pattern and Practice) PowerShell commands, you can access and manipulate SharePoint objects easily.
  • Prerequisite: You have to install cmdlets to work in PnP PowerShell.

How to run PnP PowerShell command in SharePoint?

  • First, open powershell ise.
  • powershell ise
  • Make sure you run it in Administrator Mode.
  • Now, copy and paste the code mentioned below and click on Run Script as shown in the screenshot.
  • powershell ise run command

  • # Provide credentials over here
  • $creds = (New-Object System.Management.Automation.PSCredential "<<UserName>>",(ConvertTo-SecureString "<<Password>>" -AsPlainText -Force))
  •  
  • # Provide URL of the Site over here
  • # If you do not wish to pass credentials hard coded then you can use: -Credentials (Get-Credential). This will prompt to enter credentials
  • Connect-PnPOnline -Url http://MyServer/sites/MySiteCollection -Credentials $creds
  •  
  • # (1) copyRoleAssignments(Boolean) - Specifies whether to copy the role assignments from the parent or not.
  • # If the value is false, the collection of role assignments must contain only 1 role assignment containing the current user after the operation
  •  
  • # (2) clearSubscopes(Boolean) - clearsubscopes parameter is true, the role assignments for all child objects will be cleared and those objects will inherit role assignments from the current object after this call.
  • # If the clearsubscopes parameter is false, the role assignments for all child objects which do not inherit role assignments from their parent must remain unchanged.
  •  
  • # "copyRoleAssignments" and "clearSubscopes" are Switch Parameters.
  • # A "Switch Parameter" does not take a value. If it is written in code, it turns on the "action" otherwise taken as false.
  •  
  • # to reset BreakRoleInheritence execute "-CopyRoleAssignments"
  •  
  • Set-PnPList -Identity "Documents" -BreakRoleInheritance -ClearSubscopes 
  •  
  • Disconnect-PnPOnline

Thank you for reading this article. This code was tested in SharePoint 2013


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint