Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

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

share|improve this answer
    
I have already refered the same link and code...still giving me error. I am executing my code using Windows ISE –  Ketan03 Aug 17 '12 at 9:10
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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