SharePoint Online: Grant Permission to List or Library using PowerShell

Granting access to lists, libraries and individual items in SharePoint online:
There are times you may want to grant permissions at list or library level to users and groups in SharePoint online. Say for e.g. You may want to provide read access at site level and edit rights on individual list level. So, to grant permissions to lists and libraries, as a first step we have to stop inheriting permissions from its parent and then apply unique security permissions to any level underneath site collection such as: Sub-site, List, Library or list items.

How to grant access to a list or library in SharePoint online:
  • Go to the target list or library settings (From the library page, Click on Library tab on the ribbon >> Select list settings. If modern UI is enabled, head on to Site connects and click settings from the list context menu)
  • On the List Settings page, in the permissions and management group, click on "Permissions for this list" link.
  • In the permissions page, if the list is inheriting permissions from parent, we have to break the permission inheritance. Click on "Stop inheriting Permissions" button.
  • Now, from the ribbon, click Grant Permissions button from Grant group.
  •  In the Share dialog box, in the designated text box, enter names or email addresses. 
    sharepoint online grant list permissions using powershell
  • Click the Show Options button and then specify email invitation option, appropriate permission level such as edit.
  •  Click Share
SharePoint Online - PowerShell to Grant permissions to List or Library to a User or Group:
List permissions can be manipulated with PowerShell. Here is the a typical SharePoint online set permissions PowerShell script
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Configuration Parameters
$SiteURL= ""
$ListName="Project Documents"
$GroupName="Project Members"

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Cred
    #Get the web and List
    #Break Permission inheritence - keep existing list permissions & Item level permissions
    Write-host -f Yellow "Permission inheritance broken..."
    #Get the group or user
    $Group =$Web.SiteGroups.GetByName($GroupName) #For User: $Web.EnsureUser('')

    #Grant permission to Group      
    #Get the role required
    $Role = $web.RoleDefinitions.GetByName($PermissionLevel)
    $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)
    #Assign list permissions to the group
    $Permissions = $List.RoleAssignments.Add($Group,$RoleDB)
    Write-Host "Added $PermissionLevel permission to $GroupName group in $ListName list. " -foregroundcolor Green
Catch {
    write-host -f Red "Error Granting Permissions!" $_.Exception.Message

SharePoint Online: Add Permission to List using PnP PowerShell
#Config Variables
$SiteURL = ""
$ListName ="Projects"
$GroupName = "Marketing Members"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Break Permission Inheritance of the List
Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments

#Grant permission on List to User
Set-PnPListPermission -Identity $ListName -AddRole "Edit" -User $UserID

#Grant permission on list to Group
Set-PnPListPermission -Identity $ListName -AddRole "Read" -Group $GroupName
Similarly, you can use:
Set-PnPGroupPermissions -Identity GroupName -List ListName -AddRole Contribute
SharePoint Online: Grant Permission to List or Library using PowerShell SharePoint Online: Grant Permission to List or Library using PowerShell Reviewed by Salaudeen Rajack on May 01, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.