0

I'm trying to modify the permission of a library through Power Shell.

What I want to do is:

  1. I have a library with one folder for each user, but now, all this folders inherite the permissions from the library.

  2. All my Sharepoint users are Active Directory users.

  3. Each user has a folder with his Full Name as folder name. I want to break inherite in all folders and give read permission to the appropiate user (folder name = ad user name)

Have I explained it right?

2
  • if full name is folder name how are you managing it is unique?
    – Unnie
    Commented Jun 6, 2014 at 10:41
  • We don't managed this at the moment. Full name is name plus two surnames (we are in Spain), so it's really dificult to get a match. Example of folder name: "Pedro Antonio Alonso Cayuela". The folders are created manually (we don't hire people everyday) for now, so if there is a match it will be renamed and it will get its permisions manually assigned Commented Jun 6, 2014 at 10:59

1 Answer 1

0

You can try with below script, here for group you can user your user:

function GrantUserpermission($userName)
 {
  [Microsoft.SharePoint.SPUserCollection]$spusers=[Microsoft.SharePoint.SPUserCollection]$web.SiteUsers
  [Microsoft.SharePoint.SPUser]$spuser=$spusers[$userName]
if ($userName -ne $null)

{
  $sproleass=new-object Microsoft.SharePoint.SPRoleAssignment([Microsoft.SharePoint.SPPrincipal]$spuser)
  $folder.BreakRoleInheritance("true")
  $sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["Contribute"])
  $folder.RoleAssignments.Add($sproleass);
  Write-Host "Permission provided for user ", $userName
}
else
{
 Write-Host "User ""$userName"" was not found in this web!"

}

Check this below link for whole script: http://sharepoint2010tutor.blogspot.in/2011/08/grant-folder-permissionsharepoint-using.html

6
  • Thank you very much, I only need how to clear all the folder permisions before assign new ones. Commented Jun 11, 2014 at 10:48
  • $folder.BreakRoleInheritance("true") this will clear all permissions.
    – Aanchal
    Commented Jun 11, 2014 at 10:59
  • Not really, it only break inheritance, but after I've to clean the permission Commented Jun 12, 2014 at 7:16
  • I've realized that it cleans the permissions if I use BreakRoleInheritance(0) Commented Jun 12, 2014 at 8:23
  • Yes. To remove permissions use $folder.RoleAssignments.Remove($role).
    – Aanchal
    Commented Jun 12, 2014 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.