0

I'm writing a powershell script where i create some folder. I'd like to make some group on each folder. I can add my group but all the other one by default are present too.

here is how i add my group

function GrantGroupPermission{
   param($arggroupName, $argFolder)
   [Microsoft.SharePoint.SPGroupCollection]$spgroups = $web.SiteGroups
   [Microsoft.SharePoint.SPGroup]$spgroup = $spgroups[$arggroupName]
   $sproleass=new-object Microsoft.SharePoint.SPRoleAssignment([Microsoft.SharePoint.SPPrincipal]$spgroup)
   $argFolder.BreakRoleInheritance("true")
   $sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["NoDelete"])
   $argFolder.RoleAssignments.Add($sproleass)
   $argFolder.update()
   Write-Host "Permission provided for group ", $groupName

}

and the call

$folder = $mylist.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder,$terms.Name)
$folder.Update()
GrantGroupPermission $terms.Name $folder

I used this to remove all group but got an exception

foreach($role in $folder.Item.RoleAssignments)
         {
             $folder.RoleAssignments.Remove($role)
         }
1
  • what is the exception?
    – Aanchal
    Jun 25 '14 at 12:21
0

Before this line:

$sproleass.RoleDefinitionBindings.Add($web.RoleDefinitions["NoDelete"])

Try writing this line:

$sproleass.RoleDefinitionBindings.RemoveAll()

It removes all role definitions for the object. Then, when you use the Add method, it should be the only role definition for that group.

3
  • i've tried your solution without error but without succes. all the group are still there when i look on manage permission on folder Jun 25 '14 at 14:06
  • You know, I thought you meant that the one group you are trying to add still has all the permissions associated with it. What you want is to remove all the groups from the site?
    – Brandon C.
    Jun 25 '14 at 14:09
  • the group i add doesn't have permission to delete. when i go to manage permission on folder i see: This folder has unique permissions. but still have all groups Jun 26 '14 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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