0

I used the folowing stmt to add permissions to group:

$spWeb.RoleAssignments.Add($roleAssignment)

gives following error

Exception calling "Add" with "1" argument(s): "This operation is not allowed on an object that inherits permissions."

Regards, any suggestions/help would be higly appreciated

Ketan Gandhi.

2 Answers 2

1

Try this function:

function Create-SPGroupInWeb
{
 param ($Url, $GroupName, $PermissionLevel, $Description)
 $web = Get-SPWeb -Identity $Url
 if ($web.SiteGroups[$GroupName] -ne $null)
 {
  Write-Host "Group $GroupName already exists!" -foregroundcolor Red
 }
 else
 {
  $web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $Description)
  $group = $web.SiteGroups[$GroupName]
  $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)
  $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$PermissionLevel]
  $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
  $web.RoleAssignments.Add($roleAssignment)
  $web.Update()
  Write-Host "Group $GroupName created successfully" -foregroundcolor Green
 }

 $web.Dispose()
}

For more information, you can visit http://snahta.blogspot.in/2012/02/powershell-and-sharepoint-permissions.html

1
  • I have already refered the same link and code...still giving me error. I am executing my code using Windows ISE
    – Ketan03
    Aug 17, 2012 at 9:10
1

There needs to be a call to $web.BreakRoleInheritance(true) before adding any role assignments. The "true" means that it copies the existing permissions when it breaks inheritance, with false it starts with no permissions.

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.