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

  • # 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


© 2019 Code SharePoint