How to grant permission to the user or group in the SharePoint list using powershell

In this blog we will be seeing how to grant permission to the user or group in the SharePoint list using powershell.

Go to the List (Shared documents) => Library Settings =>Permissions and Management => Permission for this document library => Grant permissions.

Add the user\group and grant the permissions.

Same thing can be achieved using the powershell script. 

Powershell Script:

# --------Input Parameters
$groupName="NT AUTHORITY\authenticated users"
$siteURL="http://servername:1111/"
$listName="Shared Documents"
$site=Get-SPSite  $ siteURL
$web=$site.RootWeb
$list=$web.lists[$listName]
$collRoleDefinitions = $web.RoleDefinitions;
$collRoleAssignments = $list.RoleAssignments;
$list.BreakRoleInheritance($false);
$user=$web.EnsureUser($userName);
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($user.LoginName, $user.Email, $user.Name, $user.Notes);
$collRoleDefinitionBindings = $roleAssignment.RoleDefinitionBindings;
$collRoleDefinitionBindings.Add($collRoleDefinitions["Contribute"]);
$collRoleAssignments.Add($roleAssignment);
$list.Update(); 


grantpermission1.gif

Ebook Download
View all
Learn
View all