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)
   Write-Host "Permission provided for group ", $groupName


and the call

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

I used this to remove all group but got an exception

foreach($role in $folder.Item.RoleAssignments)
  • what is the exception?
    – Aanchal
    Jun 25, 2014 at 12:21

1 Answer 1


Before this line:


Try writing this line:


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.

  • 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, 2014 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, 2014 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, 2014 at 6:19

Your Answer

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

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