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 need to create a new RoleDefinition and apply it to a group. Is that possible? How can I do that?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Yes that is possible. You need to use CSOM. Look at this example:

Write-Host "Opening $tenancySiteCollectionUrl ... " -NoNewLine
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($tenancySiteCollectionUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $securePassword)

$web = $ctx.Web
$ctx.Load($web)

Write-Host "OK" -ForegroundColor Green -BackgroundColor Black

Write-Host "Creating the 'Contribute - No Deletion' RoleDefinition ... " -NoNewLine
$permissions = New-Object "Microsoft.SharePoint.Client.BasePermissions"
$permissions.Set([Microsoft.SharePoint.Client.PermissionKind]::AddListItems)
$permissions.Set([Microsoft.SharePoint.Client.PermissionKind]::ViewListItems)
$permissions.Set([Microsoft.SharePoint.Client.PermissionKind]::EditListItems)

$roleDefinitionCreationInfo = New-Object "Microsoft.SharePoint.Client.RoleDefinitionCreationInformation"
$roleDefinitionCreationInfo.Name = "$roleDefinitionName"
$roleDefinitionCreationInfo.Description = "Can view, add, and update list items and documents"
$roleDefinitionCreationInfo.BasePermissions = $permissions
$web.RoleDefinitions.Add($roleDefinitionCreationInfo)

Try
{
    $ctx.ExecuteQuery()
    Write-Host "Done" -ForegroundColor Green -BackgroundColor Black
}
Catch [system.exception]
{
    Write-Error $ex
    break
}

Then you need to modify your existing group in this way:

    New-SPOSiteGroup "$($tenancySiteCollectionUrl)" -Group "$($groupName)" -PermissionLevels "Contribute"
share|improve this answer

you can also use the powershell to create the same thing

$web = Get-SPWeb http://dmg-10
$permname = "PermName1"



#create role def
$roledef = New-Object Microsoft.SharePoint.SPRoleDefinition
$roledef.BasePermissions = [Microsoft.SharePoint.SPBasePermissions]::FullMask -bxor [Microsoft.SharePoint.SPBasePermissions]::ManageSubwebs
#[enum]::GetValues([Microsoft.SharePoint.SPRights]) | ?{$_.value__ -band $roledef.BasePermissions}

$roledef.Name = $permname
$web.RoleDefinitions.Add($roledef)
$web.Update()

#remove other role assignments (ie. Full Control)
$web.RoleAssignments.Remove($web.AssociatedOwnerGroup)
$web.AssociatedOwnerGroup.Update()
$web.Update()

#assign role def to group
$roledef = $web.RoleDefinitions[$permname]
$roleassign = new-object Microsoft.SharePoint.SPRoleAssignment($web.AssociatedOwnerGroup)
$roleassign.RoleDefinitionBindings.Add($roledef);
$web.RoleAssignments.Add($roleassign)
$web.AssociatedOwnerGroup.Update()
$web.Update()

Source: http://www.gbois.com/view/5/PowerShell-SharePoint-Creating-Role-Definition-and-Applying-to-a-Group

share|improve this answer
    
does that work on SP Online? –  Gaetanu May 20 at 14:52

You could also use

New-SPOPermissionLevel

To create the RoleDefinition and New-SPOGroup if you want to create a group with that RoleDefinition.

share|improve this answer

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.