Event Receiver and Elevated Privileges

Jan 26, 2011 at 6:37 PM

Hello Christian,

First: Great solution, thank you for your work.
Maybe you can give us a tip for our problem:
we want to change list item permissions with the event receiver sp 2010.
Our users has only Contribute permissions. When we try to change the permissions ,something like

function itemadded() {

if($item.HasUniqueRoleAssignments -eq $false) {
$itm.BreakRoleInheritance($true)
}

$user = $web.AllUsers["DOMAIN\user"]
$roledef = $web.RoleDefinitions["Vollzugirff"]
$roleass = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
$roleass.RoleDefinitionBindings.Add($roledef)
$item.RoleAssignments.Add($roleass)
$item.Update()

}

We get an error. I think, the event receiver is running under the user permissions.

Is there a way to run the powershell code with elevated privileges?

Thank you

Regards

Marc

Oct 8, 2012 at 12:27 PM

Hello,

is there a solution for this cause?

I have the same problem, that users with contribute permission can´t  BreakRoleInheritance via the eventreceiver at itemadded.

Oct 8, 2012 at 1:35 PM
Edited Oct 8, 2012 at 1:35 PM

Hello,

I use this code:

if($item.HasUniqueRoleAssignments -eq $false) {
    $w = Get-SPWeb -webUrl $web.Url
    $l = $w.Lists[$list.ID]
    $i = $l.GetItemByID($item.ID)
    $i.BreakRoleInheritance($false, $true)
.......
}

 In this case using System Account context.