SharePoint Online: Grant Access to All Lists and Libraries with Unique Permission using PowerShell

Requirement: Grant Access to All Lists and Libraries with Unique Permission in SharePoint Online.

How to Set Permissions on All Lists and Libraries with Broken Inheritance?
We've a SharePoint Online site with a bunch of lists and document libraries uniquely permission-ed. How to we quickly find unique permissioned lists and add users or groups to it? Well, here is how:
  • Navigate to your SharePoint Online Site >> Click on Settings >> Site Settings 
  • In Site Settings page, Click on "Site Permissions" link under "Users and Permissions" group.
  • In the site permissions page, at the top, You'll see "Some content on this site has different permission from what you see here. Click on "Show these Items" link.
    grant access to lists with unique permission in sharepoint online
  • You'll get a page with all lists and libraries which are using unique permission. If you want to grant permission to any of these lists, just click on "Manage Permissions" link and provide desired permission.
    sharepoint online grant access to all unique permissioned lists
BTW, if lists and libraries with unique permissions have any existing SharePoint group in it, we can add the new user to that group (E.g. "Site Member") to make permissions simpler. However, that may not be the case always!

PowerShell to Provide Access to All Unique Permission-ed Lists and Libraries
While its straightforward to grant access to lists with unique permission, providing access to large number of lists through web browser interface would be inefficient. So, Here is the PowerShell script to add a user or group to all lists with broken inheritance.
#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/Neo"
$UserID = "Salaudeen@crescent.com"
$GroupName = "Neo Site Owners"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Get All Lists and Libraries
$Lists  = Get-PnPList -Includes HasUniqueRoleAssignments
$ExcludedLists = ("Preservation Hold Library", "Site Collection Images", "Style Library")

#Filter Lists with Unique Permission, Non-Hidden and Not In Excluded List
$UniqueLists = $Lists | Where {$_.HasUniqueRoleAssignments -eq $true -and $_.Hidden -eq $false -and $_.Title -notin $ExcludedLists}

#Iterate through each list 
ForEach($List in $UniqueLists)
{
    #Grant Edit permission on List to User
    Set-PnPListPermission -Identity $List -AddRole "Edit" -User $UserID 
 
    #Grant "Full Control" permission on list to SharePoint Group
    Set-PnPListPermission -Identity $List -AddRole "Full Control" -Group $GroupName

    Write-host "Granted Permissions on List:"$List.Title
}
SharePoint Online: Grant Access to All Lists and Libraries with Unique Permission using PowerShell SharePoint Online: Grant Access to All Lists and Libraries with Unique Permission using PowerShell Reviewed by Salaudeen Rajack on April 17, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.