Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
Created April 15, 2015 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamNaj/f9a52748b318d23813b8 to your computer and use it in GitHub Desktop.
Save AdamNaj/f9a52748b318d23813b8 to your computer and use it in GitHub Desktop.
ACL Manipolation
function Add-ItemAccess{
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Items.Item]$item,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$roleName)
$myRole = Get-Role $roleName
# Get the current accessrules
$accessRules = $item.Security.GetAccessRules();
# Apply read access for the "roleName " to the current item
# and all it's children
$accessRules.Helper.AddAccessPermission($myRole,
[Sitecore.Security.AccessControl.AccessRight]::ItemRead,
[Sitecore.Security.AccessControl.PropagationType]::Any,
[Sitecore.Security.AccessControl.AccessPermission]::Allow);
# Write the rules back to the item
$item.Editing.BeginEdit();
$item.Security.SetAccessRules($accessRules);
$item.Editing.EndEdit() | Out-Null
}
#Now you can simply pipe items into the function as follows (item /sitecore/content/home item (rights cascading)):
Get-Item master:\content\home | Add-ItemAccess -RoleName sitecore\Designer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment