SharePoint Online: Grant Permission to List or Library using PowerShell
Grant 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:
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 typical SharePoint Online set permissions PowerShell script :
SharePoint Online: Add Permission to List using PnP PowerShell
Let us use PnP PowerShell to add permissions in SharePoint Online list.
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 the 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.
- 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 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= "https://crescent.sharepoint.com/sites/Projects/" $ListName="Project Documents" $GroupName="Project Members" $PermissionLevel="Read" #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 $Web=$Ctx.Web $List=$web.Lists.GetByTitle($ListName) #Break Permission inheritence - keep existing list permissions & Item level permissions $List.BreakRoleInheritance($True,$True) $Ctx.ExecuteQuery() Write-host -f Yellow "Permission inheritance broken..." #Get the group or user $Group =$Web.SiteGroups.GetByName($GroupName) #For User: $Web.EnsureUser('[email protected]') $Ctx.load($Group) $Ctx.ExecuteQuery() #Grant permission to Group #Get the role required $Role = $web.RoleDefinitions.GetByName($PermissionLevel) $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx) $RoleDB.Add($Role) #Assign list permissions to the group $Permissions = $List.RoleAssignments.Add($Group,$RoleDB) $List.Update() $Ctx.ExecuteQuery() 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
Let us use PnP PowerShell to add permissions in SharePoint Online list.
#Config Variables $SiteURL = "https://crescenttech.sharepoint.com/sites/Marketing" $ListName ="Projects" $UserID="[email protected]" $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 $GroupNameSimilarly, you can use this PowerShell to assign permissions to list:
Set-PnPGroupPermissions -Identity GroupName -List ListName -AddRole ContributeTo remove user or group from list permissions: SharePoint Online: Remove User or Group from List Permissions using PowerShell
Hi.
ReplyDeleteDoes groups need to be mail enabled? i keeps getting error that the group dont exist, but if i use the gui i can ad it?
No! But Group must be created already in SharePoint.
Delete